├── LICENSE.txt ├── MigrationGuide.md ├── README.md ├── Roadmap.md ├── include └── spinecpp │ ├── Animation.h │ ├── AnimationState.h │ ├── AnimationStateData.h │ ├── Atlas.h │ ├── AtlasAttachmentLoader.h │ ├── Attachment.h │ ├── AttachmentLoader.h │ ├── Bone.h │ ├── BoneData.h │ ├── BoundingBoxAttachment.h │ ├── Color.h │ ├── Event.h │ ├── EventData.h │ ├── IkConstraint.h │ ├── IkConstraintData.h │ ├── MeshAttachment.h │ ├── PathAttachment.h │ ├── PathConstraint.h │ ├── PathConstraintData.h │ ├── PoolTrackEntryFactory.h │ ├── RegionAttachment.h │ ├── Skeleton.h │ ├── SkeletonBounds.h │ ├── SkeletonData.h │ ├── SkeletonJson.h │ ├── Skin.h │ ├── Slot.h │ ├── SlotData.h │ ├── Timeline.h │ ├── Timelines.h │ ├── TrackEntryFactory.h │ ├── TransformConstraint.h │ ├── TransformConstraintData.h │ ├── Vector.h │ ├── VertexAttachment.h │ ├── extension.h │ └── spinecpp.h ├── src └── spinecpp │ ├── Animation.cpp │ ├── AnimationState.cpp │ ├── AnimationStateData.cpp │ ├── Atlas.cpp │ ├── AtlasAttachmentLoader.cpp │ ├── AttachmentLoader.cpp │ ├── Bone.cpp │ ├── IkConstraint.cpp │ ├── MeshAttachment.cpp │ ├── PathConstraint.cpp │ ├── PoolTrackEntryFactory.cpp │ ├── RegionAttachment.cpp │ ├── Skeleton.cpp │ ├── SkeletonBounds.cpp │ ├── SkeletonData.cpp │ ├── SkeletonJson.cpp │ ├── Skin.cpp │ ├── Slot.cpp │ ├── Timelines.cpp │ ├── TransformConstraint.cpp │ └── VertexAttachment.cpp └── third_party ├── chobo └── vector_ptr.hpp └── sajson ├── LICENSE.txt └── sajson.h /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Spine Runtimes Software License 2 | Version 2.4 3 | 4 | Copyright (c) 2013-2016, Esoteric Software 5 | Copyright (c) 2016, Chobolabs 6 | All rights reserved. 7 | 8 | You are granted a perpetual, non-exclusive, non-sublicensable and 9 | non-transferable license to use, install, execute and perform the Spine 10 | Runtimes Software (the "Software") and derivative works solely for personal 11 | or internal use. Without the written permission of Esoteric Software (see 12 | Section 2 of the Spine Software License Agreement), you may not (a) modify, 13 | translate, adapt or otherwise create derivative works, improvements of 14 | the Software or develop new applications using the Software or (b) remove, 15 | delete, alter or obscure any trademarks or any copyright, trademark, patent 16 | or other intellectual property or proprietary rights notices on or in the 17 | Software, including any copy thereof. Redistributions in binary or source 18 | form must include this license and terms. 19 | 20 | THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 21 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /MigrationGuide.md: -------------------------------------------------------------------------------- 1 | This is a guide for migrating from spine-c to spine-cpp. 2 | 3 | ## API 4 | 5 | Spine-cpp uses C++ objects with methods in the namespace `spine`. 6 | 7 | Spine-cpp strings are of type `std::string` 8 | 9 | **spine-c** 10 | 11 | spSkeleton* skeleton; 12 | ... 13 | spSkeleton_setSkinByName(skeleton, "myskin"); 14 | 15 | **spine-cpp** 16 | 17 | spine::Skeleton* skeleton; 18 | ... 19 | std::string name = "myskin"; 20 | skeleton->setSkinByName(name); 21 | 22 | ## Integration 23 | 24 | Spine-c requires you to implement the following functions: 25 | 26 | extern "C" 27 | { 28 | void _spAtlasPage_createTexture(spAtlasPage* page, const char* path); 29 | void _spAtlasPage_disposeTexture(spAtlasPage* page); 30 | char* _spUtil_readFile(const char* path, int* length); 31 | } 32 | 33 | Conversely spine-cpp requires you to implement the following: 34 | 35 | namespace spine 36 | { 37 | void AtlasPage_createTexture(spine::Atlas::Page& page, const char* path); 38 | void AtlasPage_disposeTexture(spine::Atlas::Page& page); 39 | std::string Util_readFile(const std::string& path); 40 | } 41 | 42 | The main difference is in `Util_readFile` which must return a std::string with the file's contents. 43 | 44 | ## Creating a destroying objects 45 | 46 | Spine-cpp doesn't use the create/dispose functions, from spine-c and instead it relies on constructors and destructors. You can choose to create your spine-cpp object with `new`/`delete` or just declare them as value types. 47 | 48 | **spine-c** 49 | 50 | spAtlas* atlas = spAtlas_createFromFile("spineboy.atlas", 0); 51 | spSkeletonJson* sjson = spSkeletonJson_create(atlas); 52 | spSkeletonData* data = spSkeletonJson_readSkeletonDataFile(sjson, "spineboy.json"); 53 | spSkeletonJson_dispose(sjson); 54 | spSkeleton* skeleton = spSkeleton_create(data); 55 | spAnimationStateData* animStateData = spAnimationStateData_create(data); 56 | spAnimationState* animState = spAnimationState_create(animStateData); 57 | ... 58 | spAnimationState_dispose(animState); 59 | spSkeleton_dispose(skeleton); 60 | spAnimationStateData_dispose(animStateData); 61 | spSkeletonData_dispose(data); 62 | spAtlas_dispose(atlas); 63 | 64 | **spine-cpp** 65 | 66 | auto atlas = Atlas::createFromFile("spineboy.atlas", nullptr); 67 | SkeletonJson sjson(*atlas); 68 | auto data = sjson.readSkeletonDataFile("spineboy.json"); 69 | auto skeleton = new Skeleton(*data); 70 | auto animStateData = new AnimationStateData(*data); 71 | auto animState = new AnimationState(*animStateData); 72 | ... 73 | delete m_animState; 74 | delete m_skeleton; 75 | delete m_animStateData; 76 | delete m_skeletonData; 77 | delete m_atlas; 78 | 79 | ## Vectors 80 | 81 | Spine-cpp introduces a simple two-dimensional vector type: `spine::Vector`. It's used internally and externally, for example for texture coordinates. 82 | 83 | **spine-c** 84 | 85 | MyVec2 regionUVS[] = { 86 | { region->uvs[SP_VERTEX_X1], region->uvs[SP_VERTEX_Y1] }, 87 | { region->uvs[SP_VERTEX_X2], region->uvs[SP_VERTEX_Y2] }, 88 | { region->uvs[SP_VERTEX_X3], region->uvs[SP_VERTEX_Y3] }, 89 | { region->uvs[SP_VERTEX_X4], region->uvs[SP_VERTEX_Y4] }, 90 | }; 91 | 92 | **spine-cpp** 93 | 94 | MyVec2 regionUVS[] = { 95 | { region->uvs[0].x, region->uvs[0].y }, 96 | { region->uvs[1].x, region->uvs[1].y }, 97 | { region->uvs[2].x, region->uvs[2].y }, 98 | { region->uvs[3].x, region->uvs[3].y }, 99 | }; 100 | 101 | However for better compatibility `computeWorldVertices` functions still have an output parameter of type `float*` 102 | 103 | Some spine-c types, like `spBone`, have fields `float x, y;` or `float width, height;` or `float scaleX, scaleY;`. 104 | 105 | In spine-cpp the same same fields are spine vectors called `Vector translation;`, `Vector size;`, `Vector scale;` 106 | 107 | ## Colors 108 | 109 | Spine-cpp introduces a new type `spine::Color` which is used for color fields. Spine-c's `float r,g,b,a;` is `Color color` in spine-cpp 110 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spine-cpp 2 | 3 | The spine-cpp runtime provides functionality to load and manipulate skeletal animation from [Spine by Esoteric Software](http://esotericsoftware.com). 4 | 5 | Spine-cpp has been developed by [Chobolabs](http://www.chobolabs.com/) for our upcoming title [Mayhem](http://playmayhem.com/) 6 | 7 | Spine-cpp uses C++11. 8 | 9 | ## Usage 10 | 11 | ### Migrating from spine-c 12 | 13 | Please read the [migration guide](https://github.com/Chobolabs/spine-cpp/blob/master/MigrationGuide.md). 14 | 15 | ### Integrating spine-cpp into a new project 16 | 17 | *TBD* 18 | 19 | ## Limitations 20 | 21 | spine-cpp works with data exported from Spine 3.4. 22 | 23 | Like the spine-c runtime binary loading is not yet supported. 24 | 25 | There may be bugs not present in spine-c (mainly in code paths not utilized by our software). Issue reports or pull requests for such would be welcome. 26 | 27 | No custom allocation options (yet), except for animation state track entries. 28 | 29 | ## Differences from spine-c 30 | 31 | * Written in C++11 with virtual functions instead of spine-c's C-style polymorphism (Unfortunately it also means slower compile-time) 32 | * Uses a fork of [sajson](https://github.com/chadaustin/sajson) to load json files which provides much faster load time. The time spent in json parsing is about a half of spine-c's. 33 | * Utilizes more cache-friendly data structures which improve performance of the animation state update and world vertex generation. The observed gain is 2-3% on desktop cpus and 10-40% on common arm cpus found on most hand-held devices (due to their lower L1 and L2 cache miss tolerance) 34 | 35 | You can also see the upcoming features in the [roadmap](https://github.com/Chobolabs/spine-cpp/blob/master/Roadmap.md). 36 | 37 | ## Other Q&A: 38 | 39 | **Should I migrate from spine-c to spine-cpp?** 40 | 41 | If you don't have custom spine-c extensions, the migration should be a really easy process. It can literally take minutes to complete. So our advice is for you to test it and see whether you get a noticeable performance improvement. 42 | 43 | Generally if your software targets a mobile platform, it would be a good idea to do so. Even if you're satisfied with the performance of your software using spine-c and you're not looking to improve it, spine-cpp uses less cpu and thus less battery power. 44 | 45 | If your software loads tens or hundreds of Spine animations you will also see improvements in load time. 46 | 47 | **How stable is spine-cpp?** 48 | 49 | We use the library in production, but we don't use all of its features (for example we don't use Events of FFD timelines). 50 | 51 | Unfortunately we can't afford to test all of the features extensively. If you choose to use spine-cpp and find a bug, we'll do our best to fix it as fast as we can. We hope that we'll be able to fix any bug in spine-cpp, which is not present in spine-c, within 24 hours of learning about it. 52 | 53 | **Will you support C++98?** 54 | 55 | Unfortunately we don't have such plans. 56 | 57 | **Why do you have so many public members instead of setters and getters?** 58 | 59 | We wanted to make the migration from spine-c as easy as possible. For example we (and probably a lot of other users) modify some of the values in Spine's data structures, and after a migration the code for this will remain pretty much the same. 60 | 61 | Plus it's much more convenient to write `bone.rotation += x;` instead of `bone.setRotation(bone.getRotation() + x);` 62 | 63 | **Why are some types `class` and some `struct`?** 64 | 65 | The idea behind the differentiation was that types that can be constructed on their own, without depending on other types of the library are `struct`. Those are mainly the `data` types. 66 | 67 | We too are not entirely satisfied with the current differentiation and it is subject to change. 68 | 69 | **Why did you choose the include path `spinecpp` instead of just `spine`?** 70 | 71 | This is mainly for our own convenience because we often run spine-c and spine-cpp side by side to check for the consistency of our implementation and the differences in performance. Since both libraries have the same include file names (like, say, `Animation.h`) we need to differentiate between them somehow. 72 | 73 | ## Licensing 74 | 75 | This is a derivative work of the official spine-c library by Esoteric Software and, as such, is subject to the Spine Runtimes Software License. See [LICENSE.txt](https://github.com/Chobolabs/spine-cpp/blob/master/LICENSE.txt) for details 76 | 77 | This Spine Runtime may only be used for personal or internal use, typically to evaluate Spine before purchasing. If you would like to incorporate a Spine Runtime into your applications, distribute software containing a Spine Runtime, or modify a Spine Runtime, then you will need a valid [Spine license](https://esotericsoftware.com/spine-purchase). 78 | 79 | The Spine Runtimes are developed with the intent to be used with data exported from Spine. By purchasing Spine, `Section 2` of the [Spine Software License](https://esotericsoftware.com/files/license.txt) grants the right to create and distribute derivative works of the Spine Runtimes. -------------------------------------------------------------------------------- /Roadmap.md: -------------------------------------------------------------------------------- 1 | # Spine-cpp roadmap 2 | 3 | This is a list of upcoming features sorted roughly by priority. 4 | 5 | ~~A striked out feature~~ means that it has recently been added. 6 | 7 | * ~~Linked meshes~~ 8 | * Binary file loader 9 | * Cache local timelines and timeline allocator (would lead to faster animation update) 10 | * `const char*` overloads for most `std::string` arguments to avoid needless allocations 11 | * ~~Functionality to remove duplicate timeline frames (would lead to faster animation update)~~ 12 | * Demo project 13 | * Allow custom allocators 14 | * Documentation 15 | 16 | -------------------------------------------------------------------------------- /include/spinecpp/Animation.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | struct Event; 41 | class Timeline; 42 | class Skeleton; 43 | 44 | class Animation 45 | { 46 | public: 47 | Animation(const std::string& name); 48 | ~Animation(); 49 | 50 | const std::string name; 51 | 52 | /** Poses the skeleton at the specified time for this animation. 53 | * @param lastTime The last time the animation was applied. 54 | * @param events Any triggered events are added. May be null. */ 55 | void apply(Skeleton& skeleton, float lastTime, float time, int loop, std::vector* outEvents) const; 56 | 57 | /** Poses the skeleton at the specified time for this animation mixed with the current pose. 58 | * @param lastTime The last time the animation was applied. 59 | * @param events Any triggered events are added. May be null. 60 | * @param alpha The amount of this animation that affects the current pose. */ 61 | void mix(Skeleton& skeleton, float lastTime, float time, int loop, std::vector* outEvents, float alpha) const; 62 | 63 | // Calls clearIdentityFrames for all timelines. See the comment in Timeline.h for more info. 64 | void clearIdentityFramesFromTimelines(); 65 | 66 | float duration = 0; 67 | std::vector timelines; 68 | }; 69 | 70 | } -------------------------------------------------------------------------------- /include/spinecpp/AnimationState.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | struct AnimationStateData; 41 | struct Event; 42 | 43 | class AnimationState; 44 | class Animation; 45 | class Skeleton; 46 | 47 | class TrackEntryFactory; 48 | 49 | enum class EventType 50 | { 51 | Anim_Start, 52 | Anim_End, 53 | Anim_Complete, 54 | Anim_Event, 55 | }; 56 | 57 | typedef std::function AnimationStateListener; 58 | 59 | struct TrackEntry 60 | { 61 | TrackEntry(const AnimationState& state, const Animation& anim); 62 | ~TrackEntry(); 63 | 64 | const AnimationState& state; 65 | TrackEntry* previous = nullptr; 66 | TrackEntry* next = nullptr; 67 | const Animation& animation; 68 | int loop = false; // kept as int for alignment purposes 69 | float delay = 0; 70 | float time = 0; 71 | float lastTime = -1; 72 | float endTime = 0; 73 | float timeScale = 1; 74 | 75 | float mixTime = 0; 76 | float mixDuration = 0; 77 | float mix = 1; 78 | 79 | AnimationStateListener listener; 80 | void* rendererObject = nullptr; 81 | }; 82 | 83 | class AnimationState 84 | { 85 | public: 86 | AnimationState(const AnimationStateData& data, TrackEntryFactory* trackEntryFactory = nullptr); 87 | ~AnimationState(); 88 | 89 | void update(float delta); 90 | void apply(Skeleton& skeleton); 91 | 92 | void clearTracks(); 93 | void clearTrack(int trackIndex); 94 | 95 | // Set the current animation. Any queued animations are cleared. 96 | TrackEntry* setAnimationByName(int trackIndex, const std::string& animationName, bool loop); 97 | TrackEntry* setAnimation(int trackIndex, const Animation& animation, bool loop); 98 | 99 | // Adds an animation to be played delay seconds after the current or last queued animation, taking into account any mix 100 | // duration. 101 | TrackEntry* addAnimationByName(int trackIndex, const std::string& animationName, bool loop, float delay); 102 | TrackEntry* addAnimation(int trackIndex, const Animation& animation, bool loop, float delay); 103 | 104 | TrackEntry* getCurrent(int trackIndex); 105 | 106 | const AnimationStateData& data; 107 | float timeScale = 1; 108 | AnimationStateListener listener; 109 | 110 | std::vector tracks; 111 | 112 | void* rendererObject = nullptr; 113 | 114 | TrackEntryFactory& trackEntryFactory; 115 | 116 | private: 117 | void setCurrent(int index, TrackEntry* entry); 118 | void disposeAllEntries(TrackEntry* entry); 119 | TrackEntry* expandToIndex(int index); 120 | 121 | std::vector m_events; 122 | }; 123 | 124 | } 125 | -------------------------------------------------------------------------------- /include/spinecpp/AnimationStateData.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | class Animation; 41 | struct SkeletonData; 42 | 43 | struct AnimationStateData 44 | { 45 | public: 46 | AnimationStateData(const SkeletonData& skeletonData); 47 | 48 | void setMixByName(const std::string& fromName, const std::string& toName, float duration); 49 | void setMix(const Animation* from, const Animation* to, float duration); 50 | 51 | /* Returns 0 if there is no mixing between the animations. */ 52 | float getMix(const Animation* from, const Animation* to) const; 53 | 54 | const SkeletonData& skeletonData; 55 | float defaultMix = 0; 56 | 57 | private: 58 | 59 | struct ToEntry 60 | { 61 | const Animation* animation; 62 | float duration; 63 | }; 64 | 65 | struct FromEntry 66 | { 67 | const Animation* animation; 68 | std::vector toEntries; 69 | }; 70 | 71 | std::vector m_fromEntries; 72 | }; 73 | 74 | } 75 | -------------------------------------------------------------------------------- /include/spinecpp/Atlas.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | class Atlas 41 | { 42 | public: 43 | enum class Format 44 | { 45 | Unknown, 46 | Alpha, 47 | Intensity, 48 | Luminance, 49 | RGB565, 50 | RGBA4444, 51 | RGB888, 52 | RGBA8888 53 | }; 54 | 55 | enum class Filter 56 | { 57 | Unknown, 58 | Nearest, 59 | Linear, 60 | Mipmap, 61 | Mipmap_Nearest_Nearest, 62 | Mipmap_Linear_Nearest, 63 | Mipmap_Nearest_Linear, 64 | Mipmap_Linear_Linear 65 | }; 66 | 67 | enum class Wrap 68 | { 69 | MirroredRepeat, 70 | ClampToEdge, 71 | Repeat 72 | }; 73 | 74 | struct Page 75 | { 76 | Page(const Atlas& atlas, const std::string& name) 77 | : atlas(atlas) 78 | , name(name) 79 | {} 80 | 81 | ~Page(); // dispose of texture 82 | 83 | const Atlas& atlas; 84 | const std::string name; 85 | Format format; 86 | Filter minFilter, magFilter; 87 | Wrap uWrap = Wrap::MirroredRepeat, vWrap = Wrap::MirroredRepeat; 88 | 89 | void* rendererObject = nullptr; 90 | int width = 0, height = 0; 91 | }; 92 | 93 | struct Region 94 | { 95 | Region(const Page& page, const std::string& name) 96 | : page(page) 97 | , name(name) 98 | {} 99 | 100 | const Page& page; 101 | const std::string name; 102 | 103 | int x, y, width, height; 104 | float u, v, u2, v2; 105 | int offsetX, offsetY; 106 | int originalWidth, originalHeight; 107 | int index; 108 | bool rotate; 109 | bool flip; 110 | std::vector splits; 111 | std::vector pads; 112 | }; 113 | 114 | ~Atlas(); 115 | 116 | // Image files referenced in the atlas file will be prefixed with dir. 117 | static Atlas* create(const char* begin, int length, const std::string& prefixDir, void* rendererObject); 118 | 119 | // Image files referenced in the atlas file will be prefixed with the directory containing the atlas file. 120 | static Atlas* createFromFile(const char* path, void* rendererObject); 121 | 122 | // Returns nullptr if the region was not found. 123 | const Region* findRegion(const std::string& name) const; 124 | 125 | std::vector pages; 126 | std::vector regions; 127 | 128 | void* rendererObject; 129 | }; 130 | 131 | } 132 | -------------------------------------------------------------------------------- /include/spinecpp/AtlasAttachmentLoader.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include "AttachmentLoader.h" 35 | 36 | namespace spine 37 | { 38 | 39 | class Atlas; 40 | 41 | class AtlasAttachmentLoader : public AttachmentLoader 42 | { 43 | public: 44 | AtlasAttachmentLoader(const Atlas& atlas); 45 | 46 | protected: 47 | virtual Attachment* createAttachmentImpl(const Skin& skin, Attachment::Type type, const std::string& name, const std::string& path) override; 48 | 49 | private: 50 | const Atlas& m_atlas; 51 | }; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /include/spinecpp/Attachment.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | 36 | namespace spine 37 | { 38 | 39 | class AttachmentLoader; 40 | 41 | class Attachment 42 | { 43 | public: 44 | enum class Type 45 | { 46 | Region, 47 | BoundingBox, 48 | Mesh, 49 | LinkedMesh, 50 | Path, 51 | }; 52 | 53 | Attachment(const std::string& name, const Type type) 54 | : name(name) 55 | , type(type) 56 | {} 57 | 58 | virtual ~Attachment() {} 59 | 60 | const std::string name; 61 | const Type type; 62 | 63 | // loader used to create this attachment 64 | // used to be notified when the attachment is about to be destroyed 65 | AttachmentLoader* loader = nullptr; 66 | }; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /include/spinecpp/AttachmentLoader.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include "Attachment.h" 35 | 36 | namespace spine 37 | { 38 | 39 | class Skin; 40 | 41 | class AttachmentLoader 42 | { 43 | public: 44 | virtual ~AttachmentLoader() {} 45 | 46 | std::string error1; 47 | std::string error2; 48 | 49 | // Called to create each attachment. Returns 0 to not load an attachment. If 0 is returned and setError was 50 | // called, an error occurred. 51 | Attachment* createAttachment(const Skin& skin, Attachment::Type type, const std::string& name, const std::string& path); 52 | 53 | // Called after the attachment has been fully loaded, for custom configuration by the user 54 | // Use it to set the loader, if you want onDestroyingAttachment to be called for it 55 | virtual void configureAttachment(Attachment* attachment) {} 56 | 57 | // Called just before the attachment is destroyed. Use it to release allocations made in configureAttachment. 58 | virtual void onDestroyingAttachment(Attachment* attachment) {} 59 | 60 | protected: 61 | virtual Attachment* createAttachmentImpl(const Skin& skin, Attachment::Type type, const std::string& name, const std::string& path) = 0; 62 | 63 | void setError(const std::string& e1, const std::string& e2); 64 | void setUnknownTypeError(Attachment::Type type); 65 | }; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /include/spinecpp/Bone.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | class Skeleton; 41 | 42 | struct Bone 43 | { 44 | public: 45 | static void setYDown(bool yDown); 46 | static bool isYDown(); 47 | 48 | Bone(const BoneData& data, const Skeleton& skeleton, Bone* parent); 49 | 50 | const std::string& getName() const { return data.name; } 51 | 52 | void setToSetupPose(); 53 | void updateWorldTransform(); 54 | void updateWorldTransformWith(Vector translation, float rotation, Vector scale, Vector shear); 55 | 56 | float getWorldRotationX() const; 57 | float getWorldRotationY() const; 58 | float getWorldScaleX() const; 59 | float getWorldScaleY() const; 60 | 61 | float worldToLocalRotationX() const; 62 | float worldToLocalRotationY() const; 63 | 64 | void rotateWorld(float degrees); 65 | void updateLocalTransform(); 66 | 67 | void worldToLocal(Vector world, Vector& outLocal); 68 | void localToWorld(Vector local, Vector& outWorld); 69 | 70 | bool isRoot() const { return !parent; } 71 | 72 | // links 73 | const BoneData& data; 74 | const Skeleton& skeleton; 75 | Bone* const parent; 76 | std::vector children; 77 | 78 | // Logical data 79 | 80 | // user data 81 | Vector translation; 82 | float rotation; 83 | Vector scale; 84 | Vector shear; 85 | 86 | float appliedRotation; 87 | 88 | // Physical data 89 | 90 | // world tranform 2x2 matrix 91 | float a, b; 92 | float c, d; 93 | 94 | Vector worldPos; 95 | Vector worldSign; 96 | 97 | // Internal data 98 | int/*bool*/ sorted; 99 | 100 | private: 101 | static bool m_isYDown; 102 | }; 103 | 104 | } 105 | -------------------------------------------------------------------------------- /include/spinecpp/BoneData.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include "Vector.h" 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | struct BoneData 41 | { 42 | BoneData(int index, const std::string& name, const BoneData* parent) 43 | : index(index) 44 | , name(name) 45 | , parent(parent) 46 | , translation(0, 0) 47 | , scale(1, 1) 48 | , shear(0, 0) 49 | {} 50 | 51 | const int index; 52 | const std::string name; 53 | const BoneData* const parent; 54 | float length = 0; 55 | Vector translation; 56 | float rotation = 0; 57 | Vector scale; 58 | Vector shear; 59 | bool inheritRotation = true, inheritScale = true; 60 | }; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /include/spinecpp/BoundingBoxAttachment.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | #include 38 | 39 | namespace spine 40 | { 41 | 42 | class Slot; 43 | 44 | class BoundingBoxAttachment : public VertexAttachment 45 | { 46 | public: 47 | BoundingBoxAttachment(const std::string& name) : VertexAttachment(name, Attachment::Type::BoundingBox) 48 | { 49 | } 50 | }; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /include/spinecpp/Color.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | 36 | namespace spine 37 | { 38 | 39 | struct Color 40 | { 41 | Color() {}; 42 | Color(float r, float g, float b, float a) 43 | : r(r), g(g), b(b), a(a) 44 | {} 45 | 46 | float& at(size_t i) 47 | { 48 | return *(reinterpret_cast(this) + i); 49 | } 50 | 51 | float r, g, b, a; 52 | }; 53 | 54 | inline bool operator==(const Color& c1, const Color& c2) 55 | { 56 | return c1.r == c2.r && c1.g == c2.g && c1.b == c2.b && c1.a == c2.a; 57 | } 58 | 59 | inline bool operator!=(const Color& c1, const Color& c2) 60 | { 61 | return c1.r != c2.r || c1.g != c2.g || c1.b != c2.b || c1.a == c2.a; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /include/spinecpp/Event.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | 36 | namespace spine 37 | { 38 | 39 | struct Event 40 | { 41 | Event(float eventTime, const EventData& eventData) 42 | : data(eventData) 43 | , time(eventTime) 44 | {} 45 | 46 | const EventData& data; 47 | const float time; 48 | 49 | int intValue; 50 | float floatValue; 51 | std::string stringValue; 52 | }; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /include/spinecpp/EventData.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | 36 | namespace spine 37 | { 38 | 39 | struct EventData 40 | { 41 | EventData(const std::string& eventName) 42 | : name(eventName) 43 | {} 44 | 45 | const std::string name; 46 | int intValue = 0; 47 | float floatValue = 0.f; 48 | std::string stringValue; 49 | }; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /include/spinecpp/IkConstraint.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | 36 | namespace spine 37 | { 38 | 39 | class Skeleton; 40 | struct Bone; 41 | 42 | class IkConstraint 43 | { 44 | public: 45 | IkConstraint(const IkConstraintData& data, Skeleton& skeleton); 46 | 47 | const std::string& getName() const { return data.name; } 48 | 49 | void apply(); 50 | 51 | static void apply1(Bone& bone, Vector target, float alpha); 52 | static void apply2(Bone& parent, Bone& child, Vector target, int bendDirection, float alpha); 53 | 54 | const IkConstraintData& data; 55 | 56 | std::vector bones; 57 | 58 | Bone* target; 59 | 60 | int bendDirection; 61 | float mix; 62 | 63 | int level; 64 | }; 65 | 66 | } 67 | -------------------------------------------------------------------------------- /include/spinecpp/IkConstraintData.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | 36 | #include 37 | 38 | namespace spine 39 | { 40 | 41 | struct IkConstraintData 42 | { 43 | IkConstraintData(const std::string& name) 44 | : name(name) 45 | {} 46 | 47 | const std::string name; 48 | std::vector bones; 49 | 50 | const BoneData* target = nullptr; 51 | int bendDirection = 1; 52 | float mix = 1; 53 | }; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /include/spinecpp/MeshAttachment.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | namespace spine 41 | { 42 | 43 | class Slot; 44 | 45 | class MeshAttachment : public VertexAttachment 46 | { 47 | public: 48 | MeshAttachment(const std::string& name, const std::string& path); 49 | 50 | void updateUVs(); 51 | 52 | void setParentMesh(const MeshAttachment* parentMesh); 53 | const MeshAttachment* getParentMesh() const { return m_parentMesh; } 54 | 55 | const void* rendererObject = nullptr; 56 | 57 | int regionOffsetX = 0, regionOffsetY = 0; // Pixels stripped from the bottom left, unrotated. 58 | int regionWidth = 0, regionHeight = 0; // Unrotated, stripped pixel size. 59 | int regionOriginalWidth = 0, regionOriginalHeight = 0; // Unrotated, unstripped pixel size. 60 | Vector regionUV = Vector(0, 0); 61 | Vector regionUV2 = Vector(0, 0); 62 | bool regionRotate = false; 63 | 64 | const std::string path; 65 | 66 | chobo::vector_ptr regionUVs; 67 | std::vector uvs; 68 | 69 | // Chobo: actually indices 70 | chobo::vector_ptr triangles; 71 | 72 | Color color = Color(1, 1, 1, 1); 73 | 74 | int hullLength = 0; 75 | 76 | int/*bool*/ inheritDeform = false; 77 | 78 | // Nonessential. 79 | chobo::vector_ptr edges; 80 | Vector size = Vector(0, 0); 81 | 82 | private: 83 | const MeshAttachment* m_parentMesh = nullptr; 84 | std::vector m_regionUVs; 85 | std::vector m_triangles; 86 | std::vector m_edges; 87 | }; 88 | 89 | } 90 | -------------------------------------------------------------------------------- /include/spinecpp/PathAttachment.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | 36 | namespace spine 37 | { 38 | 39 | class PathAttachment : public VertexAttachment 40 | { 41 | public: 42 | PathAttachment(const std::string& name) 43 | : VertexAttachment(name, Attachment::Type::Path) 44 | {} 45 | 46 | std::vector lengths; 47 | int/*bool*/ closed = false; 48 | int constantSpeed = 0; 49 | }; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /include/spinecpp/PathConstraint.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | #include 38 | 39 | namespace spine 40 | { 41 | 42 | struct Bone; 43 | class Slot; 44 | class Skeleton; 45 | class PathAttachment; 46 | 47 | class PathConstraint 48 | { 49 | public: 50 | PathConstraint(const PathConstraintData& data, Skeleton& skeleton); 51 | 52 | const std::string& getName() const { return data.name; } 53 | 54 | void apply(); 55 | 56 | const PathConstraintData& data; 57 | std::vector bones; 58 | const Slot* target; 59 | float position, spacing, rotateMix, translateMix; 60 | 61 | std::vector spaces; 62 | 63 | struct PositionData 64 | { 65 | Vector position; 66 | float data; // different things depending on the type of constraint 67 | }; 68 | std::vector positions; 69 | std::vector world; 70 | std::vector curves; 71 | std::vector lengths; 72 | 73 | std::array segments; 74 | 75 | private: 76 | void computeWorldPositions(); 77 | void addBeforePosition(float pos, int o); 78 | void addAfterPosition(float pos, int i, int o); 79 | void addCurvePosition(float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, bool tangents, int o); 80 | }; 81 | 82 | } 83 | -------------------------------------------------------------------------------- /include/spinecpp/PathConstraintData.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | struct BoneData; 41 | struct SlotData; 42 | 43 | enum class PositionMode 44 | { 45 | Fixed, Percent 46 | }; 47 | 48 | enum class SpacingMode 49 | { 50 | Length, Fixed, Percent 51 | }; 52 | 53 | enum class RotateMode 54 | { 55 | Tangent, Chain, ChainScale 56 | }; 57 | 58 | struct PathConstraintData 59 | { 60 | PathConstraintData(const std::string& name) 61 | : name(name) 62 | {} 63 | 64 | const std::string name; 65 | std::vector bones; 66 | const SlotData* target = nullptr; 67 | 68 | PositionMode positionMode = PositionMode::Fixed; 69 | SpacingMode spacingMode = SpacingMode::Length; 70 | RotateMode rotateMode = RotateMode::Tangent; 71 | 72 | float offsetRotation = 0; 73 | float position = 0, spacing = 0, rotateMix = 0, translateMix = 0; 74 | }; 75 | 76 | } 77 | -------------------------------------------------------------------------------- /include/spinecpp/PoolTrackEntryFactory.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include "TrackEntryFactory.h" 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | namespace spine 41 | { 42 | 43 | // Provides a pool for animation track entries. 44 | // Helps with keeping them cache-local. 45 | // Using this makes sense if you mix many animations into a state. 46 | // If your typical case is to have 1 or 2 tracks, you probably won't see a big benefit from this. 47 | class PoolTrackEntryFactory : public TrackEntryFactory 48 | { 49 | public: 50 | PoolTrackEntryFactory(size_t pageSize); 51 | ~PoolTrackEntryFactory(); 52 | 53 | virtual TrackEntry* createTrackEntry(const AnimationState& state, const Animation& anim) override; 54 | virtual void destroyTrackEntry(TrackEntry* entry) override; 55 | 56 | private: 57 | struct Page 58 | { 59 | Page(size_t size); 60 | ~Page(); 61 | 62 | TrackEntry* newEntry(const AnimationState& state, const Animation& anim); 63 | void destroyEntry(TrackEntry* e); 64 | 65 | bool OwnsEntry(TrackEntry* e) const; 66 | 67 | char* const buffer; 68 | const size_t numElements; 69 | size_t numFreeElems; 70 | }; 71 | 72 | std::vector m_pages; 73 | }; 74 | 75 | } -------------------------------------------------------------------------------- /include/spinecpp/RegionAttachment.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | namespace spine 39 | { 40 | 41 | struct Bone; 42 | 43 | class RegionAttachment : public Attachment 44 | { 45 | public: 46 | RegionAttachment(const std::string& name, const std::string& path); 47 | 48 | void setUVs(float u, float v, float u2, float v2, bool rotate); 49 | void updateOffset(); 50 | 51 | size_t getVerticesCount() const { return 4; } 52 | 53 | void computeWorldVertices(const Bone& bone, float* outVertices) const; 54 | 55 | const std::string path; 56 | Vector translation = Vector(0, 0); 57 | Vector scale = Vector(1, 1); 58 | float rotation = 0; 59 | Vector size = Vector(0, 0); 60 | Color color = Color(1, 1, 1, 1); 61 | 62 | const void* rendererObject; 63 | 64 | int regionOffsetX, regionOffsetY; 65 | int regionWidth, regionHeight; 66 | int regionOriginalWidth, regionOriginalHeight; 67 | 68 | Vector offset[4]; 69 | Vector uvs[4]; 70 | }; 71 | 72 | } 73 | -------------------------------------------------------------------------------- /include/spinecpp/Skeleton.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include "SkeletonData.h" 35 | #include "Slot.h" 36 | #include "Skin.h" 37 | #include "IkConstraint.h" 38 | #include "TransformConstraint.h" 39 | #include "PathConstraint.h" 40 | 41 | namespace spine 42 | { 43 | 44 | class Skeleton 45 | { 46 | public: 47 | Skeleton(const SkeletonData& data); 48 | 49 | /* Caches information about bones and constraints. Must be called if bones or constraints, or weighted path attachments 50 | * are added or removed. */ 51 | void updateCache(); 52 | void updateWorldTransform(); 53 | 54 | /* Sets the bones, constraints, and slots to their setup pose values. */ 55 | void setToSetupPose(); 56 | /* Sets the bones and constraints to their setup pose values. */ 57 | void setBonesToSetupPose(); 58 | void setSlotsToSetupPose(); 59 | 60 | // sets draw order to identity 61 | void resetDrawOrder(); 62 | 63 | // assumes input points to a buffer of indices of size at least m_slots.size(); 64 | void setDrawOrder(const int* drawOrder); 65 | 66 | /* Returns 0 if the bone was not found. */ 67 | Bone* findBone(const std::string& name); 68 | const Bone* findBone(const std::string& name) const; 69 | /* Returns -1 if the bone was not found. */ 70 | int findBoneIndex(const std::string& name) const; 71 | 72 | const Bone& getRoot() const { return bones.front(); } 73 | Bone& getRoot() { return bones.front(); } 74 | 75 | /* Returns 0 if the slot was not found. */ 76 | const Slot* findSlot(const std::string& name) const; 77 | /* Returns -1 if the slot was not found. */ 78 | int findSlotIndex(const std::string& name) const; 79 | 80 | /* Sets the skin used to look up attachments before looking in the SkeletonData defaultSkin. Attachments from the new skin are 81 | * attached if the corresponding attachment from the old skin was attached. If there was no old skin, each slot's setup mode 82 | * attachment is attached from the new skin. 83 | * @param skin May be 0.*/ 84 | void setSkin(const Skin* skin); 85 | /* Returns false if the skin was not found. See setSkin. 86 | * @param skinName May be empty. */ 87 | bool setSkinByName(const std::string& name); 88 | 89 | const Skin* getSkin() { return m_skin; } 90 | 91 | /* Returns 0 if the slot or attachment was not found. */ 92 | const Attachment* getAttachmentForSlotName(const std::string& slotName, const std::string& attachmentName) const; 93 | /* Returns 0 if the slot or attachment was not found. */ 94 | const Attachment* getAttachmentForSlotIndex(int slotIndex, const std::string& attachmentName) const; 95 | /* Returns 0 if the slot or attachment was not found. 96 | * @param attachmentName May be 0. */ 97 | bool setAttachment(const std::string& slotName, const std::string& attachmentName); 98 | 99 | /* Returns 0 if the IK constraint was not found. */ 100 | const IkConstraint* findIkConstraint(const std::string& name) const; 101 | 102 | /* Returns 0 if the transform constraint was not found. */ 103 | const TransformConstraint* findTransformConstraint(const std::string& name) const; 104 | 105 | const PathConstraint* findPathConstraint(const std::string& name) const; 106 | 107 | void update(float deltaTime); 108 | 109 | const SkeletonData& data; 110 | 111 | std::vector bones; 112 | 113 | std::vector slots; 114 | std::vector drawOrder; // pointers from to m_slots 115 | 116 | std::vector ikConstraints; 117 | std::vector ikConstraintsSorted; 118 | 119 | std::vector transformConstraints; 120 | 121 | std::vector pathConstraints; 122 | 123 | Color color; 124 | 125 | float time = 0; 126 | 127 | bool flipX = false, flipY = false; 128 | Vector translation = Vector(0, 0); 129 | 130 | private: 131 | const Skin* m_skin = nullptr; 132 | 133 | enum class UpdateCacheType 134 | { 135 | Bone, 136 | IkConstraint, 137 | PathConstraint, 138 | TransformConstraint, 139 | }; 140 | 141 | void sortBone(Bone& b); 142 | void sortReset(std::vector& bones); 143 | void sortPathConstraintAttachment(const Skin& skin, int slotIndex, Bone& slotBone); 144 | void sortPathConstraintAttachmentBones(const Attachment* attachment, Bone& slotBone); 145 | 146 | struct UpdateCacheElem 147 | { 148 | UpdateCacheElem(Bone& b) 149 | : data(&b) 150 | , type(UpdateCacheType::Bone) 151 | {} 152 | 153 | UpdateCacheElem(IkConstraint& ik) 154 | : data(&ik) 155 | , type(UpdateCacheType::IkConstraint) 156 | {} 157 | 158 | UpdateCacheElem(PathConstraint& p) 159 | : data(&p) 160 | , type(UpdateCacheType::PathConstraint) 161 | {} 162 | 163 | UpdateCacheElem(TransformConstraint& t) 164 | : data(&t) 165 | , type(UpdateCacheType::TransformConstraint) 166 | {} 167 | 168 | void* data; 169 | UpdateCacheType type; 170 | }; 171 | std::vector m_updateCache; 172 | }; 173 | 174 | } 175 | -------------------------------------------------------------------------------- /include/spinecpp/SkeletonBounds.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | 36 | #include 37 | 38 | namespace spine 39 | { 40 | 41 | class Skeleton; 42 | class BoundingBoxAttachment; 43 | 44 | struct Polygon 45 | { 46 | std::vector vertices; 47 | 48 | bool containsPoint(Vector v) const; 49 | bool intersectsSegment(Vector a, Vector b) const; 50 | }; 51 | 52 | class SkeletonBounds 53 | { 54 | public: 55 | SkeletonBounds(); 56 | ~SkeletonBounds(); 57 | 58 | void update(const Skeleton& skeleton, bool updateAabb); 59 | 60 | /** Returns true if the axis aligned bounding box contains the point. */ 61 | bool aabbContainsPoint(Vector pt) const; 62 | 63 | /** Returns true if the axis aligned bounding box intersects the line segment. */ 64 | bool aabbIntersectsSegment(Vector a, Vector b) const; 65 | 66 | /** Returns true if the axis aligned bounding box intersects the axis aligned bounding box of the specified bounds. */ 67 | bool aabbIntersectsSkeleton(const SkeletonBounds& bounds) const; 68 | 69 | /** Returns the first bounding box attachment that contains the point, or null. When doing many checks, it is usually more 70 | * efficient to only call this method if spSkeletonBounds_aabbContainsPoint returns true. */ 71 | const BoundingBoxAttachment* containsPoint(Vector pt) const; 72 | 73 | /** Returns the first bounding box attachment that contains the line segment, or null. When doing many checks, it is usually 74 | * more efficient to only call this method if spSkeletonBounds_aabbIntersectsSegment returns true. */ 75 | const BoundingBoxAttachment* intersectsSegment(Vector a, Vector b) const; 76 | 77 | /** Returns the polygon for the specified bounding box, or null. */ 78 | const Polygon* getPolygon(const BoundingBoxAttachment& boundingBox) const; 79 | 80 | 81 | struct Bounds 82 | { 83 | const BoundingBoxAttachment* boundingBox; 84 | Polygon polygon; 85 | }; 86 | 87 | const std::vector& getBounds() { return m_bounds; } 88 | const Vector& getMin() const { return m_min; } 89 | const Vector& getMax() const { return m_max; } 90 | 91 | private: 92 | std::vector m_bounds; 93 | 94 | Vector m_min, m_max; 95 | }; 96 | 97 | } -------------------------------------------------------------------------------- /include/spinecpp/SkeletonData.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | namespace spine 44 | { 45 | 46 | struct SkeletonData 47 | { 48 | std::string version; 49 | std::string hash; 50 | 51 | Vector size = Vector(0, 0); 52 | 53 | std::vector bones; 54 | std::vector slots; 55 | std::vector skins; 56 | Skin* defaultSkin = nullptr; 57 | std::vector events; 58 | std::vector animations; 59 | std::vector ikConstraints; 60 | std::vector transformConstraints; 61 | std::vector pathConstraints; 62 | 63 | const BoneData* findBone(const char* boneName) const; 64 | int findBoneIndex(const char* boneName) const; 65 | 66 | const SlotData* findSlot(const char* slotName) const; 67 | int findSlotIndex(const char* slotName) const; 68 | 69 | const Skin* findSkin(const char* skinName) const; 70 | 71 | const EventData* findEvent(const char* eventName) const; 72 | 73 | const Animation* findAnimation(const char* animationName) const; 74 | 75 | const IkConstraintData* findIkConstraint(const char* constraintName) const; 76 | int findIkConstraintIndex(const char* constraintName) const; 77 | 78 | const TransformConstraintData* findTransformConstraint(const char* constraintName) const; 79 | int findTransformConstraintIndex(const char* constraintName) const; 80 | 81 | const PathConstraintData* findPathConstraint(const char* constraintName) const; 82 | int findPathConstraintIndex(const char* constraintName) const; 83 | }; 84 | 85 | } 86 | -------------------------------------------------------------------------------- /include/spinecpp/SkeletonJson.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | class AttachmentLoader; 41 | class Atlas; 42 | struct SkeletonData; 43 | class Animation; 44 | struct CurveFrame; 45 | class MeshAttachment; 46 | class VertexAttachment; 47 | 48 | namespace sajson 49 | { 50 | class value; 51 | } 52 | 53 | class SkeletonJson 54 | { 55 | public: 56 | SkeletonJson(AttachmentLoader& loader); 57 | SkeletonJson(const Atlas& atlas); 58 | ~SkeletonJson(); 59 | 60 | const std::string& getError() const { return m_error; } 61 | 62 | SkeletonData* readSkeletonData(const std::string& json); 63 | SkeletonData* readSkeletonDataFile(const std::string& path); 64 | 65 | void setScale(float s) { m_scale = s; } 66 | 67 | private: 68 | void setError(const std::string& e1, const std::string& e2); 69 | 70 | void readAnimation(Animation& outAnim, const SkeletonData& skeletonData, const sajson::value& json); 71 | void readCurve(CurveFrame& frame, const sajson::value& json); 72 | void readVertices(const sajson::value& json, VertexAttachment& attachment, int verticesLength); 73 | 74 | struct LinkedMesh 75 | { 76 | LinkedMesh(MeshAttachment* mesh, const char* skin, int slotIndex, const char* parent) 77 | : mesh(mesh) 78 | , skin(skin) 79 | , slotIndex(slotIndex) 80 | , parent(parent) 81 | {} 82 | 83 | MeshAttachment* mesh; 84 | const char* skin; 85 | int slotIndex; 86 | const char* parent; 87 | }; 88 | 89 | float m_scale = 1.f; 90 | bool m_ownsLoader; 91 | AttachmentLoader* m_loader; 92 | std::string m_error; 93 | 94 | std::vector m_linkedMeshes; 95 | }; 96 | 97 | } -------------------------------------------------------------------------------- /include/spinecpp/Skin.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | class Skeleton; 41 | class SkinEntry; 42 | class Attachment; 43 | 44 | class Skin 45 | { 46 | public: 47 | Skin(const std::string& name); 48 | ~Skin(); 49 | 50 | const std::string name; 51 | 52 | // The skin will take ownership of the attachment. 53 | void addAttachment(int slotIndex, const std::string& name, Attachment* attachment); 54 | 55 | // Returns nullptr if the attachment was not found. 56 | const Attachment* getAttachment(int slotIndex, const char* attachmentName) const; 57 | 58 | // Returns nullptr if the slot or attachment was not found. 59 | const char* getAttachmentName(int slotIndex, int attachmentIndex) const; 60 | 61 | // Attach each attachment in this skin if the corresponding attachment in oldSkin is currently attached. 62 | void attachAll(Skeleton& skeleton, const Skin& oldSkin) const; 63 | 64 | private: 65 | friend class SkeletonJson; 66 | friend class Skeleton; 67 | 68 | struct SkinEntry 69 | { 70 | SkinEntry(int i, const std::string& n, Attachment* a) 71 | : slotIndex(i) 72 | , name(n) 73 | , attachment(a) 74 | {} 75 | 76 | int slotIndex; 77 | std::string name; 78 | // The Skin owns the attachment. 79 | Attachment* attachment; 80 | }; 81 | 82 | std::vector m_entries; 83 | }; 84 | 85 | } -------------------------------------------------------------------------------- /include/spinecpp/Slot.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include "SlotData.h" 35 | #include "Vector.h" 36 | 37 | #include 38 | 39 | namespace spine 40 | { 41 | 42 | struct Bone; 43 | class Attachment; 44 | 45 | class Slot 46 | { 47 | public: 48 | Slot(const SlotData& data, Bone& bone); 49 | 50 | const std::string& getName() const { return data.name; } 51 | 52 | /* @param attachment May be 0 to clear the attachment for the slot. */ 53 | void setAttachment(const Attachment* attachment); 54 | const Attachment* getAttachment() const { return m_attachment; } 55 | 56 | void setAttachmentTime(float time); 57 | float getAttachmentTime() const; 58 | 59 | void setToSetupPose(); 60 | 61 | const SlotData& data; 62 | Bone& bone; 63 | Color color; 64 | std::vector attachmentVertices; 65 | 66 | private: 67 | const Attachment* m_attachment = nullptr; 68 | float m_attachmentTime; 69 | }; 70 | 71 | } 72 | -------------------------------------------------------------------------------- /include/spinecpp/SlotData.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include "BoneData.h" 35 | #include "Color.h" 36 | #include 37 | 38 | namespace spine 39 | { 40 | 41 | enum class BlendMode 42 | { 43 | Normal, 44 | Additive, 45 | Multiply, 46 | Screen, 47 | }; 48 | 49 | struct SlotData 50 | { 51 | SlotData(int index, const std::string& name, const BoneData* boneData) 52 | : index(index) 53 | , name(name) 54 | , boneData(boneData) 55 | {} 56 | 57 | const int index; 58 | const std::string name; 59 | const BoneData* const boneData; 60 | std::string attachmentName; 61 | Color color = Color(1, 1, 1, 1); 62 | BlendMode blendMode = BlendMode::Normal; 63 | }; 64 | 65 | } 66 | -------------------------------------------------------------------------------- /include/spinecpp/Timeline.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | 36 | namespace spine 37 | { 38 | 39 | struct Event; 40 | class Skeleton; 41 | 42 | class Timeline 43 | { 44 | public: 45 | enum class Type 46 | { 47 | Scale, 48 | Rotate, 49 | Translate, 50 | Shear, 51 | Color, 52 | Attachment, 53 | Event, 54 | Draworder, 55 | Deform, 56 | IkConstraint, 57 | TransformConstraint, 58 | PathConstraintPosition, 59 | PathConstraintSpacing, 60 | PathConstraintMix, 61 | }; 62 | 63 | Timeline(Type type) 64 | : type(type) 65 | {} 66 | 67 | virtual ~Timeline() {} 68 | 69 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const = 0; 70 | 71 | // Will clear all frames except the first if the transformations inside are identical. 72 | // This may be unsafe if your code relies on changing individual frames of individual timelines. 73 | // This however is probably rarely the case. If it is not, you can safely call this function to 74 | // get rid of frames left by mistake by the animators. 75 | virtual void clearIdentityFrames() = 0; 76 | 77 | private: 78 | const Type type; 79 | }; 80 | 81 | } 82 | -------------------------------------------------------------------------------- /include/spinecpp/Timelines.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include "Timeline.h" 35 | #include "Vector.h" 36 | #include "Color.h" 37 | 38 | #include 39 | 40 | namespace spine 41 | { 42 | 43 | struct Event; 44 | class Attachment; 45 | 46 | struct CurveFrame 47 | { 48 | void setLinear(); 49 | void setStepped(); 50 | 51 | // Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next. 52 | // cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of 53 | // the difference between the keyframe's values. 54 | void setCurve(Vector c1, Vector c2); 55 | 56 | float getCurvePercent(float percent) const; 57 | 58 | bool isSameCurveAs(const CurveFrame& other) const; 59 | 60 | enum class Type 61 | { 62 | Linear, 63 | Stepped, 64 | Bezier 65 | } 66 | type = Type::Linear; 67 | 68 | static const int BEZIER_SEGMENTS = 10; 69 | static const int BEZIER_DATA_SIZE = BEZIER_SEGMENTS - 1; 70 | 71 | // only used for bezier curves 72 | // points to buffer in CurveTimeline 73 | Vector* bezierData = nullptr; 74 | }; 75 | 76 | class CurveTimeline : public Timeline 77 | { 78 | protected: 79 | CurveTimeline(int framesCount, Timeline::Type type); 80 | ~CurveTimeline(); 81 | Vector* m_bezierDataBuffer = nullptr; 82 | }; 83 | 84 | class RotateTimeline : public CurveTimeline 85 | { 86 | public: 87 | RotateTimeline(int framesCount); 88 | 89 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 90 | 91 | virtual void clearIdentityFrames() override; 92 | 93 | struct Frame : public CurveFrame 94 | { 95 | float time; 96 | float angle; 97 | }; 98 | 99 | std::vector frames; 100 | int boneIndex = 0; 101 | }; 102 | 103 | class TranslateTimeline : public CurveTimeline 104 | { 105 | public: 106 | TranslateTimeline(int framesCount); 107 | 108 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 109 | 110 | virtual void clearIdentityFrames() override; 111 | 112 | struct Frame : public CurveFrame 113 | { 114 | float time; 115 | Vector translation; 116 | }; 117 | 118 | std::vector frames; 119 | int boneIndex = 0; 120 | }; 121 | 122 | class ScaleTimeline : public CurveTimeline 123 | { 124 | public: 125 | ScaleTimeline(int framesCount); 126 | 127 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 128 | 129 | virtual void clearIdentityFrames() override; 130 | 131 | struct Frame : public CurveFrame 132 | { 133 | float time; 134 | Vector scale; 135 | }; 136 | 137 | std::vector frames; 138 | int boneIndex = 0; 139 | }; 140 | 141 | class ShearTimeline : public CurveTimeline 142 | { 143 | public: 144 | ShearTimeline(int framesCount); 145 | 146 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 147 | 148 | virtual void clearIdentityFrames() override; 149 | 150 | struct Frame : public CurveFrame 151 | { 152 | float time; 153 | Vector shear; 154 | }; 155 | 156 | std::vector frames; 157 | int boneIndex = 0; 158 | }; 159 | 160 | class ColorTimeline : public CurveTimeline 161 | { 162 | public: 163 | ColorTimeline(int framesCount); 164 | 165 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 166 | 167 | virtual void clearIdentityFrames() override; 168 | 169 | struct Frame : public CurveFrame 170 | { 171 | float time; 172 | Color color; 173 | }; 174 | 175 | std::vector frames; 176 | int slotIndex = 0; 177 | }; 178 | 179 | class AttachmentTimeline : public Timeline 180 | { 181 | public: 182 | AttachmentTimeline(); 183 | 184 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 185 | 186 | virtual void clearIdentityFrames() override; 187 | 188 | struct Frame 189 | { 190 | // @param attachmentName May be empty. 191 | Frame(float time, const std::string& attachmentName) 192 | : time(time) 193 | , attachmentName(attachmentName) 194 | {} 195 | float time; 196 | std::string attachmentName; 197 | }; 198 | 199 | std::vector frames; 200 | int slotIndex = 0; 201 | }; 202 | 203 | class EventTimeline : public Timeline 204 | { 205 | public: 206 | EventTimeline(); 207 | 208 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 209 | 210 | virtual void clearIdentityFrames() override; 211 | 212 | typedef Event Frame; 213 | std::vector frames; 214 | }; 215 | 216 | class DrawOrderTimeline : public Timeline 217 | { 218 | public: 219 | DrawOrderTimeline(int framesCount, int slotsCount); 220 | ~DrawOrderTimeline(); 221 | 222 | void setFrame(int frameIndex, float time, const std::vector& drawOrder); 223 | 224 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 225 | 226 | virtual void clearIdentityFrames() override; 227 | 228 | struct Frame 229 | { 230 | float time; 231 | int* drawOrder; 232 | }; 233 | 234 | std::vector frames; 235 | 236 | private: 237 | const int m_slotsCount; 238 | int* m_drawOrderBuffer; 239 | }; 240 | 241 | class DeformTimeline : public CurveTimeline 242 | { 243 | public: 244 | DeformTimeline(int framesCount, size_t frameVerticesCount); 245 | ~DeformTimeline(); 246 | 247 | void setFrame(int frameIndex, float time, const std::vector& vertices); 248 | void setFrame(int frameIndex, float time, const std::vector& vertices); 249 | 250 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 251 | 252 | virtual void clearIdentityFrames() override; 253 | 254 | struct Frame : public CurveFrame 255 | { 256 | float time; 257 | Vector* vertices; 258 | }; 259 | 260 | std::vector frames; 261 | int slotIndex = 0; 262 | const Attachment* attachment = nullptr; 263 | 264 | private: 265 | void setFrame(int frameIndex, float time, const float* vertexData); 266 | 267 | const size_t m_frameVerticesCount; 268 | Vector* m_verticesBuffer; 269 | }; 270 | 271 | class IkConstraintTimeline : public CurveTimeline 272 | { 273 | public: 274 | IkConstraintTimeline(int framesCount); 275 | 276 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 277 | 278 | virtual void clearIdentityFrames() override; 279 | 280 | struct Frame : public CurveFrame 281 | { 282 | float time; 283 | float mix; 284 | int bendDirection; 285 | }; 286 | 287 | std::vector frames; 288 | int ikConstraintIndex = 0; 289 | }; 290 | 291 | class TransformConstraintTimeline : public CurveTimeline 292 | { 293 | public: 294 | TransformConstraintTimeline(int framesCount); 295 | 296 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 297 | 298 | virtual void clearIdentityFrames() override; 299 | 300 | struct Frame : public CurveFrame 301 | { 302 | float time; 303 | float rotateMix; 304 | float translateMix; 305 | float scaleMix; 306 | float shearMix; 307 | }; 308 | 309 | std::vector frames; 310 | int transformConstraintIndex = 0; 311 | }; 312 | 313 | class PathConstraintTimeline : public CurveTimeline 314 | { 315 | public: 316 | PathConstraintTimeline(int framesCount, Timeline::Type type); 317 | 318 | virtual void clearIdentityFrames() override; 319 | 320 | struct Frame : public CurveFrame 321 | { 322 | float time; 323 | float value; 324 | }; 325 | 326 | std::vector frames; 327 | int pathConstraintIndex = 0; 328 | 329 | protected: 330 | void applyToValue(float time, float alpha, float& inOutValue) const; 331 | }; 332 | 333 | class PathConstraintPositionTimeline : public PathConstraintTimeline 334 | { 335 | public: 336 | PathConstraintPositionTimeline(int framesCount); 337 | 338 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 339 | }; 340 | 341 | class PathConstraintSpacingTimeline : public PathConstraintTimeline 342 | { 343 | public: 344 | PathConstraintSpacingTimeline(int framesCount); 345 | 346 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 347 | }; 348 | 349 | class PathConstraintMixTimeline : public CurveTimeline 350 | { 351 | public: 352 | PathConstraintMixTimeline(int framesCount); 353 | 354 | virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector* firedEvents, float alpha) const override; 355 | 356 | virtual void clearIdentityFrames() override; 357 | 358 | struct Frame : public CurveFrame 359 | { 360 | float time; 361 | float rotateMix; 362 | float translateMix; 363 | }; 364 | 365 | std::vector frames; 366 | int pathConstraintIndex = 0; 367 | }; 368 | 369 | } -------------------------------------------------------------------------------- /include/spinecpp/TrackEntryFactory.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | namespace spine 35 | { 36 | 37 | struct TrackEntry; 38 | class AnimationState; 39 | class Animation; 40 | 41 | // Extend to provide custom track entries for an animation state 42 | class TrackEntryFactory 43 | { 44 | public: 45 | virtual ~TrackEntryFactory() {} 46 | 47 | virtual TrackEntry* createTrackEntry(const AnimationState& state, const Animation& anim) = 0; 48 | virtual void destroyTrackEntry(TrackEntry* entry) = 0; 49 | }; 50 | 51 | } -------------------------------------------------------------------------------- /include/spinecpp/TransformConstraint.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | class Skeleton; 41 | 42 | class TransformConstraint 43 | { 44 | public: 45 | TransformConstraint(const TransformConstraintData& data, Skeleton& skeleton); 46 | 47 | const std::string& getName() const { return data.name; } 48 | 49 | void apply(); 50 | 51 | const TransformConstraintData& data; 52 | std::vector bones; 53 | Bone* target; 54 | 55 | float rotateMix; 56 | float translateMix; 57 | float scaleMix; 58 | float shearMix; 59 | }; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /include/spinecpp/TransformConstraintData.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | struct TransformConstraintData 41 | { 42 | TransformConstraintData(const std::string& name) 43 | : name(name) 44 | , offsetTranslation(0, 0) 45 | , offsetScale(0, 0) 46 | {} 47 | 48 | const std::string name; 49 | std::vector bones; 50 | const BoneData* target = nullptr; 51 | float rotateMix = 0; 52 | float translateMix = 0; 53 | float scaleMix = 0; 54 | float shearMix = 0; 55 | 56 | float offsetRotation = 0; 57 | Vector offsetTranslation; 58 | Vector offsetScale; 59 | float offsetShearY = 0; 60 | }; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /include/spinecpp/Vector.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | 36 | namespace spine 37 | { 38 | 39 | struct Vector 40 | { 41 | Vector() {} 42 | Vector(float _x, float _y) 43 | : x(_x) 44 | , y(_y) 45 | {} 46 | 47 | Vector& operator=(const Vector& v) 48 | { 49 | x = v.x; 50 | y = v.y; 51 | return *this; 52 | } 53 | 54 | Vector& operator+=(const Vector& v) 55 | { 56 | x += v.x; 57 | y += v.y; 58 | return *this; 59 | } 60 | 61 | Vector& operator-=(const Vector& v) 62 | { 63 | x -= v.x; 64 | y -= v.y; 65 | return *this; 66 | } 67 | 68 | Vector& operator*=(float f) 69 | { 70 | x *= f; 71 | y *= f; 72 | return *this; 73 | } 74 | 75 | Vector& operator/=(float f) 76 | { 77 | x /= f; 78 | y /= f; 79 | return *this; 80 | } 81 | 82 | float length() const 83 | { 84 | return std::sqrt(x*x + y*y); 85 | } 86 | 87 | float angle() const 88 | { 89 | return std::atan2(y, x); 90 | } 91 | 92 | float x, y; 93 | }; 94 | 95 | inline Vector operator+(const Vector& a, const Vector& b) 96 | { 97 | return Vector(a.x + b.x, a.y + b.y); 98 | } 99 | 100 | inline Vector operator-(const Vector& a, const Vector& b) 101 | { 102 | return Vector(a.x - b.x, a.y - b.y); 103 | } 104 | 105 | inline Vector operator*(float a, const Vector& v) 106 | { 107 | return Vector(a * v.x, a * v.y); 108 | } 109 | 110 | inline Vector operator*(const Vector& v, float a) 111 | { 112 | return Vector(a * v.x, a * v.y); 113 | } 114 | 115 | inline Vector operator*(const Vector& a, const Vector& b) 116 | { 117 | return Vector(a.x * b.x, a.y * b.y); 118 | } 119 | 120 | inline bool operator==(const Vector& a, const Vector& b) 121 | { 122 | return a.x == b.x && a.y == b.y; 123 | } 124 | 125 | inline bool operator!=(const Vector& a, const Vector& b) 126 | { 127 | return a.x != b.x || a.y != b.y; 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /include/spinecpp/VertexAttachment.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | namespace spine 39 | { 40 | 41 | class Slot; 42 | 43 | class VertexAttachment : public Attachment 44 | { 45 | public: 46 | void computeWorldVertices(const Slot& slot, float* outWorldVertices) const; 47 | void computeWorldVertices(int start, int count, const Slot& slot, float* outWorldVertices, int offset) const; 48 | 49 | // indices of bones int a skeleton 50 | chobo::vector_ptr bones; 51 | 52 | // could be 53 | // pairs: x,y,x,y,x,y.... 54 | // or 55 | // triplets: x,y,weight,x,y,weight,... if there are bones 56 | chobo::vector_ptr vertices; 57 | 58 | // number of vertices (ie number of paris or triplets in vertices) 59 | int worldVerticesCount = 0; 60 | 61 | protected: 62 | VertexAttachment(const std::string& name, const Type type); 63 | 64 | std::vector m_bones; 65 | std::vector m_vectices; 66 | }; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /include/spinecpp/extension.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include "Atlas.h" 35 | 36 | #define PI 3.1415926535897932385f 37 | #define PI_DBL (PI * 2) 38 | #define DEG_RAD (PI / 180) 39 | #define RAD_DEG (180 / PI) 40 | 41 | #include 42 | 43 | // Functions that must be implemented: 44 | namespace spine 45 | { 46 | extern void AtlasPage_disposeTexture(spine::Atlas::Page& page); 47 | extern void AtlasPage_createTexture(spine::Atlas::Page& page, const char* path); 48 | extern std::string Util_readFile(const std::string& path); 49 | } 50 | -------------------------------------------------------------------------------- /include/spinecpp/spinecpp.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | -------------------------------------------------------------------------------- /src/spinecpp/Animation.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | Animation::Animation(const std::string& name) 41 | : name(name) 42 | { 43 | } 44 | 45 | Animation::~Animation() 46 | { 47 | for (auto t : timelines) 48 | { 49 | delete t; 50 | } 51 | } 52 | 53 | void Animation::apply(Skeleton& skeleton, float lastTime, float time, int loop, std::vector* outEvents) const 54 | { 55 | mix(skeleton, lastTime, time, loop, outEvents, 1); 56 | } 57 | 58 | void Animation::mix(Skeleton& skeleton, float lastTime, float time, int loop, std::vector* outEvents, float alpha) const 59 | { 60 | if (loop && duration) 61 | { 62 | time = std::fmod(time, duration); 63 | if (lastTime > 0) 64 | { 65 | lastTime = std::fmod(lastTime, duration); 66 | } 67 | } 68 | 69 | for (auto t : timelines) 70 | { 71 | t->apply(skeleton, lastTime, time, outEvents, alpha); 72 | } 73 | } 74 | 75 | void Animation::clearIdentityFramesFromTimelines() 76 | { 77 | for (auto t : timelines) 78 | { 79 | t->clearIdentityFrames(); 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/spinecpp/AnimationStateData.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | #include 34 | #include 35 | 36 | namespace spine 37 | { 38 | 39 | AnimationStateData::AnimationStateData(const SkeletonData& skeletonData) 40 | : skeletonData(skeletonData) 41 | { 42 | } 43 | 44 | void AnimationStateData::setMixByName(const std::string& fromName, const std::string& toName, float duration) 45 | { 46 | auto from = skeletonData.findAnimation(fromName.c_str()); 47 | if (!from) return; 48 | auto to = skeletonData.findAnimation(toName.c_str()); 49 | if (!to) return; 50 | 51 | setMix(from, to, duration); 52 | } 53 | 54 | void AnimationStateData::setMix(const Animation* from, const Animation* to, float duration) 55 | { 56 | /* Find existing FromEntry. */ 57 | FromEntry* fromEntry = nullptr; 58 | for (auto& fe : m_fromEntries) 59 | { 60 | if (fe.animation == from) 61 | { 62 | for (auto& te : fe.toEntries) 63 | { 64 | if (te.animation == to) 65 | { 66 | te.duration = duration; 67 | return; 68 | } 69 | } 70 | 71 | fromEntry = &fe; 72 | break; /* Add new ToEntry to the existing FromEntry. */ 73 | } 74 | } 75 | 76 | if (!fromEntry) 77 | { 78 | m_fromEntries.resize(m_fromEntries.size() + 1); 79 | fromEntry = &m_fromEntries.back(); 80 | fromEntry->animation = from; 81 | } 82 | 83 | auto& toEntries = fromEntry->toEntries; 84 | toEntries.resize(toEntries.size() + 1); 85 | toEntries.back().animation = to; 86 | toEntries.back().duration = duration; 87 | } 88 | 89 | float AnimationStateData::getMix(const Animation* from, const Animation* to) const 90 | { 91 | for (auto& fe : m_fromEntries) 92 | { 93 | if (fe.animation == from) 94 | { 95 | for (auto& te : fe.toEntries) 96 | { 97 | if (te.animation == to) 98 | { 99 | return te.duration; 100 | } 101 | } 102 | 103 | break; /* we shouldn't have two entries for the same animation */ 104 | } 105 | } 106 | 107 | return defaultMix; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/spinecpp/AtlasAttachmentLoader.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | namespace spine 40 | { 41 | 42 | AtlasAttachmentLoader::AtlasAttachmentLoader(const Atlas& atlas) 43 | : m_atlas(atlas) 44 | { 45 | } 46 | 47 | Attachment* AtlasAttachmentLoader::createAttachmentImpl(const Skin& skin, Attachment::Type type, const std::string& name, const std::string& path) 48 | { 49 | switch (type) { 50 | case Attachment::Type::Region: 51 | { 52 | auto region = m_atlas.findRegion(path); 53 | 54 | if (!region) 55 | { 56 | setError("Region not found: ", path); 57 | return nullptr; 58 | } 59 | 60 | auto attachment = new RegionAttachment(name, path); 61 | 62 | attachment->rendererObject = region; 63 | attachment->setUVs(region->u, region->v, region->u2, region->v2, region->rotate); 64 | attachment->regionOffsetX = region->offsetX; 65 | attachment->regionOffsetY = region->offsetY; 66 | attachment->regionWidth = region->width; 67 | attachment->regionHeight = region->height; 68 | attachment->regionOriginalWidth = region->originalWidth; 69 | attachment->regionOriginalHeight = region->originalHeight; 70 | 71 | return attachment; 72 | } 73 | case Attachment::Type::Mesh: 74 | case Attachment::Type::LinkedMesh: 75 | { 76 | auto region = m_atlas.findRegion(path); 77 | 78 | if (!region) 79 | { 80 | setError("Region for mesh not found: ", path); 81 | return nullptr; 82 | } 83 | 84 | auto attachment = new MeshAttachment(name, path); 85 | attachment->rendererObject = region; 86 | attachment->regionUV.x = region->u; 87 | attachment->regionUV.y = region->v; 88 | attachment->regionUV2.x = region->u2; 89 | attachment->regionUV2.y = region->v2; 90 | attachment->regionRotate = region->rotate; 91 | attachment->regionOffsetX = region->offsetX; 92 | attachment->regionOffsetY = region->offsetY; 93 | attachment->regionWidth = region->width; 94 | attachment->regionHeight = region->height; 95 | attachment->regionOriginalWidth = region->originalWidth; 96 | attachment->regionOriginalHeight = region->originalHeight; 97 | return attachment; 98 | } 99 | case Attachment::Type::BoundingBox: 100 | return new BoundingBoxAttachment(name); 101 | case Attachment::Type::Path: 102 | return new PathAttachment(name); 103 | default: 104 | setUnknownTypeError(type); 105 | return nullptr; 106 | } 107 | } 108 | 109 | } -------------------------------------------------------------------------------- /src/spinecpp/AttachmentLoader.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | 34 | namespace spine 35 | { 36 | 37 | Attachment* AttachmentLoader::createAttachment(const Skin& skin, Attachment::Type type, const std::string& name, const std::string& path) 38 | { 39 | error1.clear(); 40 | error2.clear(); 41 | return createAttachmentImpl(skin, type, name, path); 42 | } 43 | 44 | void AttachmentLoader::setError(const std::string& e1, const std::string& e2) 45 | { 46 | error1 = e1; 47 | error2 = e2; 48 | } 49 | 50 | void AttachmentLoader::setUnknownTypeError(Attachment::Type type) 51 | { 52 | char buffer[16]; 53 | sprintf(buffer, "%d", type); 54 | setError("Unknown attachment type: ", buffer); 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /src/spinecpp/Bone.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | using namespace std; 39 | 40 | namespace 41 | { 42 | 43 | inline float sin_deg(float f) 44 | { 45 | return sin(f * DEG_RAD); 46 | } 47 | 48 | inline float cos_deg(float f) 49 | { 50 | return cos(f * DEG_RAD); 51 | } 52 | 53 | } 54 | 55 | namespace spine 56 | { 57 | 58 | bool Bone::m_isYDown = false; 59 | 60 | void Bone::setYDown(bool yDown) 61 | { 62 | m_isYDown = yDown; 63 | } 64 | 65 | bool Bone::isYDown() 66 | { 67 | return m_isYDown; 68 | } 69 | 70 | Bone::Bone(const BoneData& data, const Skeleton& skeleton, Bone* parent) 71 | : data(data) 72 | , skeleton(skeleton) 73 | , parent(parent) 74 | { 75 | setToSetupPose(); 76 | } 77 | 78 | void Bone::setToSetupPose() 79 | { 80 | translation = data.translation; 81 | rotation = data.rotation; 82 | scale = data.scale; 83 | shear = data.shear; 84 | } 85 | 86 | void Bone::updateWorldTransform() 87 | { 88 | updateWorldTransformWith(translation, rotation, scale, shear); 89 | } 90 | 91 | void Bone::updateWorldTransformWith(Vector translation, float rotation, Vector scale, Vector shear) 92 | { 93 | appliedRotation = rotation; 94 | 95 | float rotationY = rotation + 90 + shear.y; 96 | float la = cos_deg(rotation + shear.x) * scale.x, lb = cos_deg(rotationY) * scale.y; 97 | float lc = sin_deg(rotation + shear.x) * scale.x, ld = sin_deg(rotationY) * scale.y; 98 | 99 | if (!parent) // Root bone. 100 | { 101 | if (skeleton.flipX) 102 | { 103 | translation.x = -translation.x; 104 | la = -la; 105 | lb = -lb; 106 | } 107 | 108 | if (skeleton.flipY != m_isYDown) 109 | { 110 | translation.y = -translation.y; 111 | lc = -lc; 112 | ld = -ld; 113 | } 114 | 115 | a = la; 116 | b = lb; 117 | c = lc; 118 | d = ld; 119 | worldPos = translation; 120 | worldSign.x = scale.x > 0 ? 1.f : -1.f; 121 | worldSign.y = scale.y > 0 ? 1.f : -1.f; 122 | 123 | return; 124 | } 125 | 126 | float pa = parent->a; 127 | float pb = parent->b; 128 | float pc = parent->c; 129 | float pd = parent->d; 130 | 131 | worldPos.x = pa * translation.x + pb * translation.y + parent->worldPos.x; 132 | worldPos.y = pc * translation.x + pd * translation.y + parent->worldPos.y; 133 | 134 | worldSign.x = parent->worldSign.x * (scale.x > 0 ? 1.f : -1.f); 135 | worldSign.y = parent->worldSign.y * (scale.y > 0 ? 1.f : -1.f); 136 | 137 | if (data.inheritRotation && data.inheritScale) 138 | { 139 | a = pa * la + pb * lc; 140 | b = pa * lb + pb * ld; 141 | c = pc * la + pd * lc; 142 | d = pc * lb + pd * ld; 143 | } 144 | else 145 | { 146 | if (data.inheritRotation) /* No scale inheritance. */ 147 | { 148 | pa = 1; 149 | pb = 0; 150 | pc = 0; 151 | pd = 1; 152 | 153 | auto p = parent; 154 | 155 | do 156 | { 157 | float cosine = cos_deg(p->appliedRotation); 158 | float sine = sin_deg(p->appliedRotation); 159 | float temp = pa * cosine + pb * sine; 160 | pb = pb * cosine - pa * sine; 161 | pa = temp; 162 | temp = pc * cosine + pd * sine; 163 | pd = pd * cosine - pc * sine; 164 | pc = temp; 165 | 166 | if (!p->data.inheritRotation) break; 167 | p = p->parent; 168 | } while (p); 169 | 170 | a = pa * la + pb * lc; 171 | b = pa * lb + pb * ld; 172 | c = pc * la + pd * lc; 173 | d = pc * lb + pd * ld; 174 | } 175 | else if (data.inheritScale) /* No rotation inheritance. */ 176 | { 177 | pa = 1; 178 | pb = 0; 179 | pc = 0; 180 | pd = 1; 181 | 182 | auto p = parent; 183 | 184 | do { 185 | float za, zb, zc, zd; 186 | 187 | float psx = p->scale.x, psy = p->scale.y; 188 | float cosine = cos_deg(p->appliedRotation); 189 | float sine = sin_deg(p->appliedRotation); 190 | za = cosine * psx; zb = sine * psy; zc = sine * psx; zd = cosine * psy; 191 | float temp = pa * za + pb * zc; 192 | pb = pb * zd - pa * zb; 193 | pa = temp; 194 | temp = pc * za + pd * zc; 195 | pd = pd * zd - pc * zb; 196 | pc = temp; 197 | 198 | if (psx >= 0) sine = -sine; 199 | temp = pa * cosine + pb * sine; 200 | pb = pb * cosine - pa * sine; 201 | pa = temp; 202 | temp = pc * cosine + pd * sine; 203 | pd = pd * cosine - pc * sine; 204 | pc = temp; 205 | 206 | if (!p->data.inheritScale) break; 207 | p = p->parent; 208 | } while (p); 209 | 210 | 211 | a = pa * la + pb * lc; 212 | b = pa * lb + pb * ld; 213 | c = pc * la + pd * lc; 214 | d = pc * lb + pd * ld; 215 | } 216 | else 217 | { 218 | a = la; 219 | b = lb; 220 | c = lc; 221 | d = ld; 222 | } 223 | 224 | if (skeleton.flipX) 225 | { 226 | a = -a; 227 | b = -b; 228 | } 229 | 230 | if (skeleton.flipY != m_isYDown) 231 | { 232 | c = -c; 233 | d = -d; 234 | } 235 | } 236 | } 237 | 238 | float Bone::getWorldRotationX() const 239 | { 240 | return atan2(c, a) * RAD_DEG; 241 | } 242 | 243 | float Bone::getWorldRotationY() const 244 | { 245 | return atan2(d, b) * RAD_DEG; 246 | } 247 | 248 | float Bone::getWorldScaleX() const 249 | { 250 | return sqrt(a * a + c * c) * worldSign.x; 251 | } 252 | 253 | float Bone::getWorldScaleY() const 254 | { 255 | return sqrt(b * b + d * d) * worldSign.y; 256 | } 257 | 258 | float Bone::worldToLocalRotationX() const 259 | { 260 | if (!parent) return rotation; 261 | return atan2(parent->a * c - parent->c * a, parent->d * a - parent->b * c) * RAD_DEG; 262 | } 263 | 264 | float Bone::worldToLocalRotationY() const 265 | { 266 | if (!parent) return rotation; 267 | return atan2(parent->a * d - parent->c * b, parent->d * b - parent->b * d) * RAD_DEG; 268 | } 269 | 270 | void Bone::rotateWorld(float degrees) 271 | { 272 | float cosine = cos_deg(degrees), sine = sin_deg(degrees); 273 | 274 | float a = this->a, b = this->b, c = this->c, d = this->d; 275 | 276 | this->a = cosine * a - sine * c; 277 | this->b = cosine * b - sine * d; 278 | this->c = sine * a + cosine * c; 279 | this->d = sine * b + cosine * d; 280 | } 281 | 282 | /** Computes the local transform from the world transform. This can be useful to perform processing on the local transform 283 | * after the world transform has been modified directly (eg, by a constraint). 284 | *

285 | * Some redundant information is lost by the world transform, such as -1,-1 scale versus 180 rotation. The computed local 286 | * transform values may differ from the original values but are functionally the same. */ 287 | void Bone::updateLocalTransform() 288 | { 289 | if (!parent) 290 | { 291 | float det = a * d - b * c; 292 | translation = worldPos; 293 | rotation = atan2(c, a) * RAD_DEG; 294 | scale.x = sqrt(a * a + c * c); 295 | scale.y = sqrt(b * b + d * d); 296 | shear.x = 0; 297 | shear.y = atan2(a * b + c * d, det) * RAD_DEG; 298 | } 299 | else { 300 | float pa = parent->a, pb = parent->b, pc = parent->c, pd = parent->d; 301 | float pid = 1 / (pa * pd - pb * pc); 302 | float dx = worldPos.x - parent->worldPos.x, dy = worldPos.y - parent->worldPos.y; 303 | float ia = pid * pd; 304 | float id = pid * pa; 305 | float ib = pid * pb; 306 | float ic = pid * pc; 307 | float ra = ia * a - ib * c; 308 | float rb = ia * b - ib * d; 309 | float rc = id * c - ic * a; 310 | float rd = id * d - ic * b; 311 | translation.x = (dx * pd * pid - dy * pb * pid); 312 | translation.y = (dy * pa * pid - dx * pc * pid); 313 | shear.x = 0; 314 | scale.x = sqrt(ra * ra + rc * rc); 315 | if (scale.x > 0.0001f) 316 | { 317 | float det = ra * rd - rb * rc; 318 | scale.y = det / scale.x; 319 | shear.y = atan2(ra * rb + rc * rd, det) * RAD_DEG; 320 | rotation = atan2(rc, ra) * RAD_DEG; 321 | } 322 | else 323 | { 324 | scale.x = 0; 325 | scale.y = sqrt(rb * rb + rd * rd); 326 | shear.y = 0; 327 | rotation = 90 - atan2(rd, rb) * RAD_DEG; 328 | } 329 | appliedRotation = rotation; 330 | } 331 | } 332 | 333 | void Bone::worldToLocal(Vector world, Vector& outLocal) 334 | { 335 | float invDet = 1 / (a * d - b * c); 336 | float x = world.x - worldPos.x, y = world.y - worldPos.y; 337 | outLocal.x = (x * d * invDet - y * b * invDet); 338 | outLocal.y = (y * a * invDet - x * c * invDet); 339 | } 340 | 341 | void Bone::localToWorld(Vector local, Vector& outWorld) 342 | { 343 | outWorld.x = local.x * a + local.y * b + worldPos.x; 344 | outWorld.y = local.x * c + local.y * d + worldPos.y; 345 | } 346 | 347 | } 348 | -------------------------------------------------------------------------------- /src/spinecpp/IkConstraint.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | using namespace std; 40 | 41 | namespace spine 42 | { 43 | 44 | IkConstraint::IkConstraint(const IkConstraintData& data, Skeleton& skeleton) 45 | : data(data) 46 | { 47 | bendDirection = data.bendDirection; 48 | mix = data.mix; 49 | 50 | bones.reserve(data.bones.size()); 51 | 52 | for (auto bd : data.bones) 53 | { 54 | bones.emplace_back(skeleton.findBone(bd->name)); 55 | } 56 | 57 | target = skeleton.findBone(data.target->name); 58 | } 59 | 60 | void IkConstraint::apply() 61 | { 62 | switch (bones.size()) 63 | { 64 | case 1: 65 | apply1(*bones.front(), target->worldPos, mix); 66 | break; 67 | case 2: 68 | apply2(*bones.front(), *bones.back(), target->worldPos, bendDirection, mix); 69 | } 70 | } 71 | 72 | void IkConstraint::apply1(Bone& bone, Vector target, float alpha) 73 | { 74 | auto pp = bone.parent; 75 | float id = 1 / (pp->a * pp->d - pp->b * pp->c); 76 | auto pos = target - pp->worldPos; 77 | float tx = (pos.x * pp->d - pos.y * pp->b) * id - bone.translation.x, 78 | ty = (pos.y * pp->a - pos.x * pp->c) * id - bone.translation.y; 79 | 80 | float rotationIK = atan2(ty, tx) * RAD_DEG - bone.shear.x - bone.rotation; 81 | if (bone.scale.x < 0) 82 | rotationIK += 180; 83 | 84 | if (rotationIK > 180) 85 | rotationIK -= 360; 86 | else if (rotationIK < -180) 87 | rotationIK += 360; 88 | 89 | bone.updateWorldTransformWith(bone.translation, bone.rotation + rotationIK * alpha, bone.scale, bone.shear); 90 | } 91 | 92 | void IkConstraint::apply2(Bone& parent, Bone& child, Vector target, int bendDir, float alpha) 93 | { 94 | float px = parent.translation.x, py = parent.translation.y, psx = parent.scale.x, psy = parent.scale.y; 95 | float cx = child.translation.x, cy, csx = child.scale.x, cwx, cwy; 96 | int o1, o2, s2, u; 97 | auto pp = parent.parent; 98 | float tx, ty, dx, dy, l1, l2, a1, a2, r; 99 | float id, x, y; 100 | 101 | if (alpha == 0) 102 | { 103 | child.updateWorldTransform(); 104 | return; 105 | } 106 | 107 | if (psx < 0) { 108 | psx = -psx; 109 | o1 = 180; 110 | s2 = -1; 111 | } 112 | else { 113 | o1 = 0; 114 | s2 = 1; 115 | } 116 | if (psy < 0) { 117 | psy = -psy; 118 | s2 = -s2; 119 | } 120 | if (csx < 0) { 121 | csx = -csx; 122 | o2 = 180; 123 | } 124 | else 125 | o2 = 0; 126 | r = psx - psy; 127 | u = (r < 0 ? -r : r) <= 0.0001f; 128 | if (!u) { 129 | cy = 0; 130 | cwx = parent.a * cx + parent.worldPos.x; 131 | cwy = parent.c * cx + parent.worldPos.y; 132 | } 133 | else { 134 | cy = child.translation.y; 135 | cwx = parent.a * cx + parent.b * cy + parent.worldPos.x; 136 | cwy = parent.c * cx + parent.d * cy + parent.worldPos.y; 137 | } 138 | id = 1 / (pp->a * pp->d - pp->b * pp->c); 139 | x = target.x - pp->worldPos.x; 140 | y = target.y - pp->worldPos.y; 141 | tx = (x * pp->d - y * pp->b) * id - px; 142 | ty = (y * pp->a - x * pp->c) * id - py; 143 | x = cwx - pp->worldPos.x; 144 | y = cwy - pp->worldPos.y; 145 | dx = (x * pp->d - y * pp->b) * id - px; 146 | dy = (y * pp->a - x * pp->c) * id - py; 147 | l1 = sqrt(dx * dx + dy * dy); 148 | l2 = child.data.length * csx; 149 | if (u) { 150 | float cosine, a, b; 151 | l2 *= psx; 152 | cosine = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2); 153 | if (cosine < -1) cosine = -1; 154 | else if (cosine > 1) cosine = 1; 155 | a2 = acos(cosine) * bendDir; 156 | a = l1 + l2 * cosine; 157 | b = l2 * sin(a2); 158 | a1 = atan2(ty * a - tx * b, tx * a + ty * b); 159 | } 160 | else { 161 | float a = psx * l2, b = psy * l2; 162 | float aa = a * a, bb = b * b, ll = l1 * l1, dd = tx * tx + ty * ty, ta = atan2(ty, tx); 163 | float c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa; 164 | float d = c1 * c1 - 4 * c2 * c0; 165 | float minAngle = 0, minDist = std::numeric_limits::max(), minX = 0, minY = 0; 166 | float maxAngle = 0, maxDist = 0, maxX = 0, maxY = 0; 167 | float x = l1 + a, dist = x * x, angle, y; 168 | if (d >= 0) { 169 | float q = sqrt(d), r0, r1; 170 | if (c1 < 0) q = -q; 171 | q = -(c1 + q) / 2; 172 | r0 = q / c2; r1 = c0 / q; 173 | r = abs(r0) < abs(r1) ? r0 : r1; 174 | if (r * r <= dd) { 175 | y = sqrt(dd - r * r) * bendDir; 176 | a1 = ta - atan2(y, r); 177 | a2 = atan2(y / psy, (r - l1) / psx); 178 | goto outer; 179 | } 180 | } 181 | if (dist > maxDist) { 182 | maxAngle = 0; 183 | maxDist = dist; 184 | maxX = x; 185 | } 186 | x = l1 - a; 187 | dist = x * x; 188 | if (dist < minDist) { 189 | minAngle = PI; 190 | minDist = dist; 191 | minX = x; 192 | } 193 | angle = acos(-a * l1 / (aa - bb)); 194 | x = a * cos(angle) + l1; 195 | y = b * sin(angle); 196 | dist = x * x + y * y; 197 | if (dist < minDist) { 198 | minAngle = angle; 199 | minDist = dist; 200 | minX = x; 201 | minY = y; 202 | } 203 | if (dist > maxDist) { 204 | maxAngle = angle; 205 | maxDist = dist; 206 | maxX = x; 207 | maxY = y; 208 | } 209 | if (dd <= (minDist + maxDist) / 2) { 210 | a1 = ta - atan2(minY * bendDir, minX); 211 | a2 = minAngle * bendDir; 212 | } 213 | else { 214 | a1 = ta - atan2(maxY * bendDir, maxX); 215 | a2 = maxAngle * bendDir; 216 | } 217 | } 218 | outer: 219 | { 220 | float os = atan2(cy, cx) * s2; 221 | a1 = (a1 - os) * RAD_DEG + o1 - parent.rotation; 222 | if (a1 > 180) a1 -= 360; 223 | else if (a1 < -180) a1 += 360; 224 | parent.updateWorldTransformWith(Vector(px, py), parent.rotation + a1 * alpha, parent.scale, Vector(0, 0)); 225 | a2 = ((a2 + os) * RAD_DEG - child.shear.x) * s2 + o2 - child.rotation; 226 | if (a2 > 180) a2 -= 360; 227 | else if (a2 < -180) a2 += 360; 228 | child.updateWorldTransformWith(Vector(cx, cy), child.rotation + a2 * alpha, child.scale, child.shear); 229 | } 230 | } 231 | 232 | } 233 | -------------------------------------------------------------------------------- /src/spinecpp/MeshAttachment.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | namespace spine 39 | { 40 | 41 | MeshAttachment::MeshAttachment(const std::string& name, const std::string& path) 42 | : VertexAttachment(name, Attachment::Type::Mesh) 43 | , path(path) 44 | { 45 | regionUVs.reset(&m_regionUVs); 46 | triangles.reset(&m_triangles); 47 | edges.reset(&m_edges); 48 | } 49 | 50 | void MeshAttachment::updateUVs() 51 | { 52 | auto size = regionUV2 - regionUV; 53 | 54 | uvs.clear(); 55 | uvs.resize(worldVerticesCount); 56 | 57 | if (regionRotate) 58 | { 59 | for (size_t i = 0; i < uvs.size(); ++i) 60 | { 61 | auto& uv = uvs[i]; 62 | const auto& ruv = regionUVs[i]; 63 | 64 | uv.x = regionUV.x + ruv.y * size.x; 65 | uv.y = regionUV.y + size.y - ruv.x * size.y; 66 | } 67 | } 68 | else 69 | { 70 | for (size_t i = 0; i < uvs.size(); ++i) 71 | { 72 | auto& uv = uvs[i]; 73 | const auto& ruv = regionUVs[i]; 74 | 75 | uv.x = regionUV.x + ruv.x * size.x; 76 | uv.y = regionUV.y + ruv.y * size.y; 77 | } 78 | } 79 | } 80 | 81 | void MeshAttachment::setParentMesh(const MeshAttachment* parentMesh) 82 | { 83 | m_parentMesh = parentMesh; 84 | if (parentMesh) 85 | { 86 | worldVerticesCount = parentMesh->worldVerticesCount; 87 | 88 | bones = parentMesh->bones; 89 | vertices = parentMesh->vertices; 90 | 91 | regionUVs = parentMesh->regionUVs; 92 | triangles = parentMesh->triangles; 93 | 94 | hullLength = parentMesh->hullLength; 95 | 96 | edges = parentMesh->edges; 97 | 98 | size = parentMesh->size; 99 | } 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/spinecpp/PoolTrackEntryFactory.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | namespace spine 39 | { 40 | 41 | PoolTrackEntryFactory::PoolTrackEntryFactory(size_t pageSize) 42 | { 43 | m_pages.emplace_back(pageSize); 44 | } 45 | 46 | PoolTrackEntryFactory::~PoolTrackEntryFactory() 47 | { 48 | } 49 | 50 | TrackEntry* PoolTrackEntryFactory::createTrackEntry(const AnimationState& state, const Animation& anim) 51 | { 52 | for (auto& page : m_pages) 53 | { 54 | if (page.numFreeElems) 55 | { 56 | return page.newEntry(state, anim); 57 | } 58 | } 59 | 60 | m_pages.emplace_back(m_pages.front().numElements); 61 | return m_pages.back().newEntry(state, anim); 62 | } 63 | 64 | void PoolTrackEntryFactory::destroyTrackEntry(TrackEntry* entry) 65 | { 66 | for (auto& page : m_pages) 67 | { 68 | if (page.OwnsEntry(entry)) 69 | { 70 | return page.destroyEntry(entry); 71 | return; 72 | } 73 | } 74 | 75 | assert(false); // entry not owned by any page 76 | } 77 | 78 | PoolTrackEntryFactory::Page::Page(size_t size) 79 | : buffer(new char[size * sizeof(TrackEntry)]) 80 | , numElements(size) 81 | , numFreeElems(size) 82 | { 83 | memset(buffer, 0, size * sizeof(TrackEntry)); 84 | } 85 | 86 | PoolTrackEntryFactory::Page::~Page() 87 | { 88 | auto lim = numElements * sizeof(TrackEntry); 89 | for (size_t i = 0; i < lim; i += sizeof(TrackEntry)) 90 | { 91 | assert(!*(buffer + i)); 92 | } 93 | 94 | delete[] buffer; 95 | } 96 | 97 | TrackEntry* PoolTrackEntryFactory::Page::newEntry(const AnimationState& state, const Animation& anim) 98 | { 99 | assert(numFreeElems != 0); 100 | auto lim = numElements * sizeof(TrackEntry); 101 | for (size_t i = 0; i < lim; i += sizeof(TrackEntry)) 102 | { 103 | auto b = buffer + i; 104 | if (!*b) 105 | { 106 | --numFreeElems; 107 | return new (b) TrackEntry(state, anim); 108 | } 109 | } 110 | 111 | assert(false); // no free found? 112 | return nullptr; 113 | } 114 | 115 | bool PoolTrackEntryFactory::Page::OwnsEntry(TrackEntry* e) const 116 | { 117 | auto c = reinterpret_cast(e); 118 | return (c >= buffer) && (c < buffer + numElements * sizeof(TrackEntry)); 119 | } 120 | 121 | void PoolTrackEntryFactory::Page::destroyEntry(TrackEntry* e) 122 | { 123 | assert(OwnsEntry(e)); 124 | 125 | e->~TrackEntry(); 126 | *reinterpret_cast(e) = 0; 127 | 128 | // entry destroyed multiple times 129 | assert(numFreeElems < numElements); 130 | ++numFreeElems; 131 | } 132 | 133 | } -------------------------------------------------------------------------------- /src/spinecpp/RegionAttachment.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | namespace spine 40 | { 41 | 42 | RegionAttachment::RegionAttachment(const std::string& name, const std::string& path) 43 | : Attachment(name, Attachment::Type::Region) 44 | , path(path) 45 | { 46 | } 47 | 48 | void RegionAttachment::setUVs(float u, float v, float u2, float v2, bool rotate) 49 | { 50 | if (rotate) { 51 | uvs[1].x = u; 52 | uvs[1].y = v2; 53 | uvs[2].x = u; 54 | uvs[2].y = v; 55 | uvs[3].x = u2; 56 | uvs[3].y = v; 57 | uvs[0].x = u2; 58 | uvs[0].y = v2; 59 | } 60 | else { 61 | uvs[0].x = u; 62 | uvs[0].y = v2; 63 | uvs[1].x = u; 64 | uvs[1].y = v; 65 | uvs[2].x = u2; 66 | uvs[2].y = v; 67 | uvs[3].x = u2; 68 | uvs[3].y = v2; 69 | } 70 | } 71 | 72 | 73 | void RegionAttachment::updateOffset() 74 | { 75 | float regionScaleX = size.x / regionOriginalWidth * scale.x; 76 | float regionScaleY = size.y / regionOriginalHeight * scale.y; 77 | float localX = -size.x / 2 * scale.x + regionOffsetX * regionScaleX; 78 | float localY = -size.y / 2 * scale.y + regionOffsetY * regionScaleY; 79 | float localX2 = localX + regionWidth * regionScaleX; 80 | float localY2 = localY + regionHeight * regionScaleY; 81 | float radians = rotation * DEG_RAD; 82 | float cosine = std::cos(radians), sine = std::sin(radians); 83 | float localXCos = localX * cosine + translation.x; 84 | float localXSin = localX * sine; 85 | float localYCos = localY * cosine + translation.y; 86 | float localYSin = localY * sine; 87 | float localX2Cos = localX2 * cosine + translation.x; 88 | float localX2Sin = localX2 * sine; 89 | float localY2Cos = localY2 * cosine + translation.y; 90 | float localY2Sin = localY2 * sine; 91 | offset[0].x = localXCos - localYSin; 92 | offset[0].y = localYCos + localXSin; 93 | offset[1].x = localXCos - localY2Sin; 94 | offset[1].y = localY2Cos + localXSin; 95 | offset[2].x = localX2Cos - localY2Sin; 96 | offset[2].y = localY2Cos + localX2Sin; 97 | offset[3].x = localX2Cos - localYSin; 98 | offset[3].y = localYCos + localX2Sin; 99 | } 100 | 101 | void RegionAttachment::computeWorldVertices(const Bone& bone, float* vertices) const 102 | { 103 | float x = bone.skeleton.translation.x + bone.worldPos.x; 104 | float y = bone.skeleton.translation.y + bone.worldPos.y; 105 | 106 | vertices[0] = offset[0].x * bone.a + offset[0].y * bone.b + x; 107 | vertices[1] = offset[0].x * bone.c + offset[0].y * bone.d + y; 108 | vertices[2] = offset[1].x * bone.a + offset[1].y * bone.b + x; 109 | vertices[3] = offset[1].x * bone.c + offset[1].y * bone.d + y; 110 | vertices[4] = offset[2].x * bone.a + offset[2].y * bone.b + x; 111 | vertices[5] = offset[2].x * bone.c + offset[2].y * bone.d + y; 112 | vertices[6] = offset[3].x * bone.a + offset[3].y * bone.b + x; 113 | vertices[7] = offset[3].x * bone.c + offset[3].y * bone.d + y; 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/spinecpp/SkeletonBounds.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | namespace spine 41 | { 42 | 43 | bool Polygon::containsPoint(Vector pt) const 44 | { 45 | bool inside = 0; 46 | size_t prevIndex = vertices.size() - 1; 47 | 48 | for (size_t i = 0; i < vertices.size(); ++i) 49 | { 50 | auto& v = vertices[i]; 51 | auto prev = vertices[prevIndex]; 52 | 53 | if ((v.y < pt.y && prev.y >= pt.y) || (prev.y < pt.y && v.y >= pt.y)) 54 | { 55 | if (v.x + (pt.y - v.y) / (prev.y - v.y) * (prev.x - v.x) < pt.x) 56 | { 57 | inside = !inside; 58 | } 59 | } 60 | prevIndex = i; 61 | } 62 | return inside; 63 | } 64 | 65 | bool Polygon::intersectsSegment(Vector a, Vector b) const 66 | { 67 | auto size = b - a; 68 | float det1 = a.x * b.y - a.y * b.x; 69 | 70 | Vector bv = vertices.back(); 71 | 72 | for (auto& v : vertices) 73 | { 74 | float det2 = bv.x * v.y - bv.y * v.x; 75 | auto vsize = bv - v; 76 | float det3 = size.x * vsize.y - size.y * vsize.x; 77 | float x = (det1 * vsize.x - size.x * det2) / det3; 78 | 79 | if (((x >= bv.x && x <= v.x) || (x >= v.x && x <= bv.x)) && ((x >= a.x && x <= b.x) || (x >= b.x && x <= a.x))) 80 | { 81 | float y = (det1 * vsize.y - size.y * det2) / det3; 82 | 83 | if (((y >= bv.y && y <= v.y) || (y >= v.y && y <= bv.y)) && ((y >= a.y && y <= b.y) || (y >= b.y && y <= a.y))) 84 | { 85 | return true; 86 | } 87 | } 88 | bv = v; 89 | } 90 | return false; 91 | } 92 | 93 | 94 | SkeletonBounds::SkeletonBounds() 95 | { 96 | 97 | } 98 | 99 | SkeletonBounds::~SkeletonBounds() 100 | { 101 | // only defined so we call the appoprite destructors here 102 | } 103 | 104 | 105 | void SkeletonBounds::update(const Skeleton& skeleton, bool updateAabb) 106 | { 107 | auto& slots = skeleton.slots; 108 | m_bounds.resize(slots.size()); 109 | 110 | m_min.x = m_min.y = std::numeric_limits::lowest(); 111 | m_max.x = m_max.y = std::numeric_limits::max(); 112 | 113 | for (size_t i = 0; i < slots.size(); ++i) 114 | { 115 | auto& slot = slots[i]; 116 | auto& bounds = m_bounds[i]; 117 | 118 | auto attachment = slot.getAttachment(); 119 | 120 | if (!attachment || attachment->type != Attachment::Type::BoundingBox) 121 | { 122 | continue; 123 | } 124 | 125 | auto bb = static_cast(attachment); 126 | bounds.boundingBox = bb; 127 | 128 | bounds.polygon.vertices.resize(bb->worldVerticesCount); 129 | bb->computeWorldVertices(slot, reinterpret_cast(bounds.polygon.vertices.data())); 130 | 131 | if (updateAabb) 132 | { 133 | for (const auto& pv : bounds.polygon.vertices) 134 | { 135 | if (pv.x < m_min.x) m_min.x = pv.x; 136 | if (pv.y < m_min.y) m_min.y = pv.y; 137 | if (pv.x > m_max.x) m_max.x = pv.x; 138 | if (pv.y > m_max.y) m_max.y = pv.y; 139 | } 140 | } 141 | } 142 | } 143 | 144 | bool SkeletonBounds::aabbContainsPoint(Vector pt) const 145 | { 146 | return pt.x >= m_min.x && pt.x <= m_max.x && pt.y >= m_min.y && pt.y <= m_max.y; 147 | } 148 | 149 | bool SkeletonBounds::aabbIntersectsSegment(Vector a, Vector b) const 150 | { 151 | if ((a.x <= m_min.x && b.x <= m_min.x) || (a.y <= m_min.y && b.y <= m_min.y) || (a.x >= m_max.x && b.x >= m_max.x) 152 | || (a.y >= m_max.y && b.y >= m_max.y)) 153 | { 154 | return false; 155 | } 156 | 157 | float m = (b.y - a.y) / (b.x - a.x); 158 | float y = m * (m_min.x - a.x) + a.y; 159 | if (y > m_min.y && y < m_max.y) return true; 160 | y = m * (m_max.x - a.x) + a.y; 161 | if (y > m_min.y && y < m_max.y) return true; 162 | float x = (m_min.y - a.y) / m + a.x; 163 | if (x > m_min.x && x < m_max.x) return true; 164 | x = (m_max.y - a.y) / m + a.x; 165 | if (x > m_min.x && x < m_max.x) return true; 166 | 167 | return false; 168 | } 169 | 170 | bool SkeletonBounds::aabbIntersectsSkeleton(const SkeletonBounds& bounds) const 171 | { 172 | return m_min.x < bounds.m_max.x && m_max.x > bounds.m_min.x && m_min.y < bounds.m_max.y && m_max.y > bounds.m_min.y; 173 | } 174 | 175 | const BoundingBoxAttachment* SkeletonBounds::containsPoint(Vector pt) const 176 | { 177 | for (auto& bounds : m_bounds) 178 | { 179 | if (bounds.polygon.containsPoint(pt)) 180 | { 181 | return bounds.boundingBox; 182 | } 183 | } 184 | 185 | return nullptr; 186 | } 187 | 188 | const BoundingBoxAttachment* SkeletonBounds::intersectsSegment(Vector a, Vector b) const 189 | { 190 | for (auto& bounds : m_bounds) 191 | { 192 | if (bounds.polygon.intersectsSegment(a, b)) 193 | { 194 | return bounds.boundingBox; 195 | } 196 | } 197 | 198 | return nullptr; 199 | } 200 | 201 | const Polygon* SkeletonBounds::getPolygon(const BoundingBoxAttachment& boundingBox) const 202 | { 203 | for (auto& bounds : m_bounds) 204 | { 205 | if (bounds.boundingBox == &boundingBox) 206 | { 207 | return &bounds.polygon; 208 | } 209 | } 210 | 211 | return nullptr; 212 | } 213 | 214 | } 215 | -------------------------------------------------------------------------------- /src/spinecpp/SkeletonData.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | 34 | namespace 35 | { 36 | template 37 | const T* findByName(const std::vector& v, const char* name) 38 | { 39 | for (auto& t : v) 40 | { 41 | if (t.name == name) 42 | { 43 | return &t; 44 | } 45 | } 46 | 47 | return nullptr; 48 | } 49 | 50 | template 51 | int findIndexByName(const std::vector& v, const char* name) 52 | { 53 | for (size_t i = 0; i < v.size(); ++i) 54 | { 55 | if (v[i].name == name) 56 | { 57 | return int(i); 58 | } 59 | } 60 | 61 | return -1; 62 | } 63 | } 64 | 65 | namespace spine 66 | { 67 | 68 | const BoneData* SkeletonData::findBone(const char* boneName) const 69 | { 70 | return findByName(bones, boneName); 71 | } 72 | 73 | int SkeletonData::findBoneIndex(const char* boneName) const 74 | { 75 | return findIndexByName(bones, boneName); 76 | } 77 | 78 | const SlotData* SkeletonData::findSlot(const char* slotName) const 79 | { 80 | return findByName(slots, slotName); 81 | } 82 | 83 | int SkeletonData::findSlotIndex(const char* slotName) const 84 | { 85 | return findIndexByName(slots, slotName); 86 | } 87 | 88 | const Skin* SkeletonData::findSkin(const char* skinName) const 89 | { 90 | return findByName(skins, skinName); 91 | } 92 | 93 | const EventData* SkeletonData::findEvent(const char* eventName) const 94 | { 95 | return findByName(events, eventName); 96 | } 97 | 98 | const Animation* SkeletonData::findAnimation(const char* animationName) const 99 | { 100 | return findByName(animations, animationName); 101 | } 102 | 103 | const IkConstraintData* SkeletonData::findIkConstraint(const char* constraintName) const 104 | { 105 | return findByName(ikConstraints, constraintName); 106 | } 107 | 108 | int SkeletonData::findIkConstraintIndex(const char* constraintName) const 109 | { 110 | return findIndexByName(ikConstraints, constraintName); 111 | } 112 | 113 | const TransformConstraintData* SkeletonData::findTransformConstraint(const char* constraintName) const 114 | { 115 | return findByName(transformConstraints, constraintName); 116 | } 117 | 118 | int SkeletonData::findTransformConstraintIndex(const char* constraintName) const 119 | { 120 | return findIndexByName(transformConstraints, constraintName); 121 | } 122 | 123 | const PathConstraintData* SkeletonData::findPathConstraint(const char* constraintName) const 124 | { 125 | return findByName(pathConstraints, constraintName); 126 | } 127 | 128 | 129 | int SkeletonData::findPathConstraintIndex(const char* constraintName) const 130 | { 131 | return findIndexByName(pathConstraints, constraintName); 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /src/spinecpp/Skin.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace spine 38 | { 39 | 40 | Skin::Skin(const std::string& name) 41 | : name(name) 42 | { 43 | 44 | } 45 | 46 | Skin::~Skin() 47 | { 48 | for (auto& e : m_entries) 49 | { 50 | if (e.attachment->loader) 51 | { 52 | e.attachment->loader->onDestroyingAttachment(e.attachment); 53 | } 54 | delete e.attachment; 55 | } 56 | } 57 | 58 | void Skin::addAttachment(int slotIndex, const std::string& name, Attachment* attachment) 59 | { 60 | m_entries.emplace_back(slotIndex, name, attachment); 61 | } 62 | 63 | const Attachment* Skin::getAttachment(int slotIndex, const char* attachmentName) const 64 | { 65 | for (auto& e : m_entries) 66 | { 67 | if (e.slotIndex == slotIndex && e.name == attachmentName) 68 | { 69 | return e.attachment; 70 | } 71 | } 72 | 73 | return nullptr; 74 | } 75 | 76 | /* Returns nullptr if the slot or attachment was not found. */ 77 | const char* Skin::getAttachmentName(int slotIndex, int attachmentIndex) const 78 | { 79 | int i = 0; 80 | for (auto& e : m_entries) 81 | { 82 | if (e.slotIndex == slotIndex) 83 | { 84 | if (i == attachmentIndex) 85 | { 86 | return e.name.c_str(); 87 | } 88 | ++i; 89 | } 90 | } 91 | 92 | return nullptr; 93 | } 94 | 95 | void Skin::attachAll(Skeleton& skeleton, const Skin& oldSkin) const 96 | { 97 | for (auto& e : oldSkin.m_entries) 98 | { 99 | auto& slot = skeleton.slots[e.slotIndex]; 100 | if (slot.getAttachment() == e.attachment) 101 | { 102 | auto newAttachment = getAttachment(e.slotIndex, e.name.c_str()); 103 | if (newAttachment) 104 | { 105 | slot.setAttachment(newAttachment); 106 | } 107 | } 108 | } 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/spinecpp/Slot.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | namespace spine 39 | { 40 | 41 | Slot::Slot(const SlotData& data, Bone& bone) 42 | : data(data) 43 | , bone(bone) 44 | { 45 | setToSetupPose(); 46 | } 47 | 48 | void Slot::setAttachment(const Attachment* attachment) 49 | { 50 | if (attachment == m_attachment) 51 | { 52 | return; 53 | } 54 | 55 | m_attachment = attachment; 56 | m_attachmentTime = bone.skeleton.time; 57 | attachmentVertices.clear(); 58 | } 59 | 60 | void Slot::setAttachmentTime(float time) 61 | { 62 | m_attachmentTime = bone.skeleton.time - time; 63 | } 64 | 65 | float Slot::getAttachmentTime() const 66 | { 67 | return bone.skeleton.time - m_attachmentTime; 68 | } 69 | 70 | void Slot::setToSetupPose() 71 | { 72 | color = data.color; 73 | 74 | if (data.attachmentName.empty()) 75 | { 76 | setAttachment(nullptr); 77 | } 78 | else 79 | { 80 | m_attachment = nullptr; 81 | auto attachment = bone.skeleton.getAttachmentForSlotIndex(data.index, data.attachmentName); 82 | setAttachment(attachment); 83 | } 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/spinecpp/TransformConstraint.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | using namespace std; 38 | 39 | namespace spine 40 | { 41 | 42 | TransformConstraint::TransformConstraint(const TransformConstraintData& data, Skeleton& skeleton) 43 | : data(data) 44 | { 45 | rotateMix = data.rotateMix; 46 | translateMix = data.translateMix; 47 | scaleMix = data.scaleMix; 48 | shearMix = data.shearMix; 49 | 50 | bones.reserve(data.bones.size()); 51 | for (auto boneData : data.bones) 52 | { 53 | bones.emplace_back(skeleton.findBone(boneData->name)); 54 | } 55 | 56 | target = skeleton.findBone(data.target->name); 57 | } 58 | 59 | void TransformConstraint::apply() 60 | { 61 | float ta = target->a, tb = target->b, tc = target->c, td = target->d; 62 | 63 | for (auto bone : bones) 64 | { 65 | if (rotateMix > 0) 66 | { 67 | float a = bone->a, b = bone->b, c = bone->c, d = bone->d; 68 | float r = atan2(tc, ta) - atan2(c, a) + data.offsetRotation * DEG_RAD; 69 | 70 | if (r > PI) r -= PI_DBL; 71 | else if (r < -PI) r += PI_DBL; 72 | r *= rotateMix; 73 | float cosine = cos(r); 74 | float sine = sin(r); 75 | bone->a = cosine * a - sine * c; 76 | bone->b = cosine * b - sine * d; 77 | bone->c = sine * a + cosine * c; 78 | bone->d = sine * b + cosine * d; 79 | } 80 | 81 | if (translateMix > 0) 82 | { 83 | Vector pos; 84 | target->localToWorld(data.offsetTranslation, pos); 85 | 86 | bone->worldPos += (pos - bone->worldPos) * translateMix; 87 | } 88 | 89 | if (scaleMix > 0) 90 | { 91 | float bs = sqrt(bone->a * bone->a + bone->c * bone->c); 92 | float ts = sqrt(ta * ta + tc * tc); 93 | float s = bs > 0.00001f ? (bs + (ts - bs + data.offsetScale.x) * scaleMix) / bs : 0; 94 | bone->a *= s; 95 | bone->c *= s; 96 | 97 | bs = sqrt(bone->b * bone->b + bone->d * bone->d); 98 | ts = sqrt(tb * tb + td * td); 99 | s = bs > 0.00001f ? (bs + (ts - bs + data.offsetScale.y) * scaleMix) / bs : 0; 100 | bone->b *= s; 101 | bone->d *= s; 102 | } 103 | 104 | if (shearMix > 0) 105 | { 106 | float b = bone->b, d = bone->d; 107 | float by = atan2(d, b); 108 | float r = atan2(td, tb) - atan2(tc, ta) - (by - atan2(bone->c, bone->a)); 109 | float s = sqrt(b * b + d * d); 110 | 111 | if (r > PI) r -= PI_DBL; 112 | else if (r < -PI) r += PI_DBL; 113 | r = by + (r + data.offsetShearY * DEG_RAD) * shearMix; 114 | bone->b = cos(r) * s; 115 | bone->d = sin(r) * s; 116 | } 117 | } 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/spinecpp/VertexAttachment.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Spine Runtimes Software License 3 | // Version 2.4 4 | // 5 | // Copyright (c) 2013-2016, Esoteric Software 6 | // Copyright (c) 2016, Chobolabs 7 | // All rights reserved. 8 | // 9 | // You are granted a perpetual, non-exclusive, non-sublicensable and 10 | // non-transferable license to use, install, execute and perform the Spine 11 | // Runtimes Software (the "Software") and derivative works solely for personal 12 | // or internal use. Without the written permission of Esoteric Software (see 13 | // Section 2 of the Spine Software License Agreement), you may not (a) modify, 14 | // translate, adapt or otherwise create derivative works, improvements of 15 | // the Software or develop new applications using the Software or (b) remove, 16 | // delete, alter or obscure any trademarks or any copyright, trademark, patent 17 | // or other intellectual property or proprietary rights notices on or in the 18 | // Software, including any copy thereof. Redistributions in binary or source 19 | // form must include this license and terms. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE AND CHOBOLABS "AS IS" AND ANY 22 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | // DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE OR CHOBOLABS BE LIABLE FOR 25 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | //////////////////////////////////////////////////////////////////////////////// 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | namespace spine 39 | { 40 | 41 | VertexAttachment::VertexAttachment(const std::string& name, const Type type) 42 | : Attachment(name, type) 43 | { 44 | bones.reset(&m_bones); 45 | vertices.reset(&m_vectices); 46 | } 47 | 48 | void VertexAttachment::computeWorldVertices(const Slot& slot, float* outWorldVertices) const 49 | { 50 | computeWorldVertices(0, worldVerticesCount * 2, slot, outWorldVertices, 0); 51 | } 52 | 53 | void VertexAttachment::computeWorldVertices(int start, int count, const Slot& slot, float* outWorldVertices, int offset) const 54 | { 55 | count += offset; 56 | auto& skeleton = slot.bone.skeleton; 57 | auto x = skeleton.translation.x; 58 | auto y = skeleton.translation.y; 59 | auto deformLength = slot.attachmentVertices.size() * 2; 60 | auto fvertices = vertices.data(); 61 | auto deform = reinterpret_cast(slot.attachmentVertices.data()); 62 | 63 | if (bones.empty()) 64 | { 65 | if (deformLength > 0) fvertices = deform; 66 | auto& bone = slot.bone; 67 | x += bone.worldPos.x; 68 | y += bone.worldPos.y; 69 | for (int v = start, w = offset; w < count; v += 2, w += 2) { 70 | float vx = fvertices[v], vy = fvertices[v + 1]; 71 | outWorldVertices[w] = vx * bone.a + vy * bone.b + x; 72 | outWorldVertices[w + 1] = vx * bone.c + vy * bone.d + y; 73 | } 74 | } 75 | else 76 | { 77 | int v = 0, skip = 0; 78 | for (int i = 0; i < start; i += 2) 79 | { 80 | int n = bones[v]; 81 | v += n + 1; 82 | skip += n; 83 | } 84 | 85 | auto& skeletonBones = skeleton.bones; 86 | if (deformLength == 0) 87 | { 88 | for (int w = offset, b = skip * 3; w < count; w += 2) { 89 | float wx = x, wy = y; 90 | int n = bones[v++]; 91 | n += v; 92 | for (; v < n; v++, b += 3) 93 | { 94 | auto& bone = skeletonBones[bones[v]]; 95 | float vx = fvertices[b], vy = fvertices[b + 1], weight = fvertices[b + 2]; 96 | wx += (vx * bone.a + vy * bone.b + bone.worldPos.x) * weight; 97 | wy += (vx * bone.c + vy * bone.d + bone.worldPos.y) * weight; 98 | } 99 | outWorldVertices[w] = wx; 100 | outWorldVertices[w + 1] = wy; 101 | } 102 | } 103 | else 104 | { 105 | for (int w = offset, b = skip * 3, f = skip << 1; w < count; w += 2) { 106 | float wx = x, wy = y; 107 | int n = bones[v++]; 108 | n += v; 109 | for (; v < n; v++, b += 3, f += 2) 110 | { 111 | auto& bone = skeletonBones[bones[v]]; 112 | float vx = fvertices[b] + deform[f], vy = fvertices[b + 1] + deform[f + 1], weight = fvertices[b + 2]; 113 | wx += (vx * bone.a + vy * bone.b + bone.worldPos.x) * weight; 114 | wy += (vx * bone.c + vy * bone.d + bone.worldPos.y) * weight; 115 | } 116 | outWorldVertices[w] = wx; 117 | outWorldVertices[w + 1] = wy; 118 | } 119 | } 120 | } 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /third_party/sajson/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Chad Austin 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | --------------------------------------------------------------------------------