no message

This commit is contained in:
gem
2025-02-18 15:21:31 +08:00
commit 2d133e56d7
1980 changed files with 465595 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/Animation.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Timeline.h>
#include <spine/ContainerUtil.h>
#include <stdint.h>
using namespace spine;
Animation::Animation(const String &name, Vector<Timeline *> &timelines, float duration) : _timelines(timelines),
_timelineIds(),
_duration(duration),
_name(name) {
assert(_name.length() > 0);
for (int i = 0; i < (int)timelines.size(); i++)
_timelineIds.put(timelines[i]->getPropertyId(), true);
}
bool Animation::hasTimeline(int id) {
return _timelineIds.containsKey(id);
}
Animation::~Animation() {
ContainerUtil::cleanUpVectorOfPointers(_timelines);
}
void Animation::apply(Skeleton &skeleton, float lastTime, float time, bool loop, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction) {
if (loop && _duration != 0) {
time = MathUtil::fmod(time, _duration);
if (lastTime > 0) {
lastTime = MathUtil::fmod(lastTime, _duration);
}
}
for (size_t i = 0, n = _timelines.size(); i < n; ++i) {
_timelines[i]->apply(skeleton, lastTime, time, pEvents, alpha, blend, direction);
}
}
const String &Animation::getName() {
return _name;
}
Vector<Timeline *> &Animation::getTimelines() {
return _timelines;
}
float Animation::getDuration() {
return _duration;
}
void Animation::setDuration(float inValue) {
_duration = inValue;
}
int Animation::binarySearch(Vector<float> &values, float target, int step) {
int low = 0;
int size = (int)values.size();
int high = size / step - 2;
if (high == 0) {
return step;
}
int current = (int)(static_cast<uint32_t>(high) >> 1);
while (true) {
if (values[(current + 1) * step] <= target)
low = current + 1;
else
high = current;
if (low == high) return (low + 1) * step;
current = (int)(static_cast<uint32_t>(low + high) >> 1);
}
}
int Animation::binarySearch(Vector<float> &values, float target) {
int low = 0;
int size = (int)values.size();
int high = size - 2;
if (high == 0) return 1;
int current = (int)(static_cast<uint32_t>(high) >> 1);
while (true) {
if (values[(current + 1)] <= target)
low = current + 1;
else
high = current;
if (low == high) return (low + 1);
current = (int)(static_cast<uint32_t>(low + high) >> 1);
}
}
int Animation::linearSearch(Vector<float> &values, float target, int step) {
for (int i = 0, last = (int)values.size() - step; i <= last; i += step) {
if (values[i] > target) {
return i;
}
}
return -1;
}

View File

@@ -0,0 +1,120 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_Animation_h
#define Spine_Animation_h
#include <spine/HashMap.h>
#include <spine/MixBlend.h>
#include <spine/MixDirection.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
#include <spine/Vector.h>
namespace spine {
class Timeline;
class Skeleton;
class Event;
class SP_API Animation : public SpineObject {
friend class AnimationState;
friend class TrackEntry;
friend class AnimationStateData;
friend class AttachmentTimeline;
friend class ColorTimeline;
friend class DeformTimeline;
friend class DrawOrderTimeline;
friend class EventTimeline;
friend class IkConstraintTimeline;
friend class PathConstraintMixTimeline;
friend class PathConstraintPositionTimeline;
friend class PathConstraintSpacingTimeline;
friend class RotateTimeline;
friend class ScaleTimeline;
friend class ShearTimeline;
friend class TransformConstraintTimeline;
friend class TranslateTimeline;
friend class TwoColorTimeline;
public:
Animation(const String &name, Vector<Timeline *> &timelines, float duration);
~Animation();
/// Applies all the animation's timelines to the specified skeleton.
/// See also Timeline::apply(Skeleton&, float, float, Vector, float, MixPose, MixDirection)
void apply(Skeleton &skeleton, float lastTime, float time, bool loop, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction);
const String &getName();
Vector<Timeline *> &getTimelines();
bool hasTimeline(int id);
float getDuration();
void setDuration(float inValue);
private:
Vector<Timeline *> _timelines;
HashMap<int, bool> _timelineIds;
float _duration;
String _name;
/// @param target After the first and before the last entry.
static int binarySearch(Vector<float> &values, float target, int step);
/// @param target After the first and before the last entry.
static int binarySearch(Vector<float> &values, float target);
static int linearSearch(Vector<float> &values, float target, int step);
};
} // namespace spine
#endif /* Spine_Animation_h */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,435 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_AnimationState_h
#define Spine_AnimationState_h
#include <spine/HasRendererObject.h>
#include <spine/MixBlend.h>
#include <spine/Pool.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
#include <spine/Vector.h>
#ifdef SPINE_USE_STD_FUNCTION
#include <functional>
#endif
namespace spine {
enum EventType {
EventType_Start,
EventType_Interrupt,
EventType_End,
EventType_Dispose,
EventType_Complete,
EventType_Event
};
class AnimationState;
class TrackEntry;
class Animation;
class Event;
class AnimationStateData;
class Skeleton;
class RotateTimeline;
#ifdef SPINE_USE_STD_FUNCTION
typedef std::function<void(AnimationState* state, EventType type, TrackEntry* entry, Event* event)> AnimationStateListener;
#else
typedef void (*AnimationStateListener)(AnimationState* state, EventType type, TrackEntry* entry, Event* event);
#endif
/// Abstract class to inherit from to create a callback object
class SP_API AnimationStateListenerObject {
public:
AnimationStateListenerObject(){};
virtual ~AnimationStateListenerObject(){};
public:
/// The callback function to be called
virtual void callback(AnimationState* state, EventType type, TrackEntry* entry, Event* event) = 0;
};
/// State for the playback of an animation
class SP_API TrackEntry : public SpineObject, public HasRendererObject {
friend class EventQueue;
friend class AnimationState;
public:
TrackEntry();
virtual ~TrackEntry();
/// The index of the track where this entry is either current or queued.
int getTrackIndex();
/// The animation to apply for this track entry.
Animation* getAnimation();
/// If true, the animation will repeat. If false, it will not, instead its last frame is applied if played beyond its duration.
bool getLoop();
void setLoop(bool inValue);
/// If true, when mixing from the previous animation to this animation, the previous animation is applied as normal instead
/// of being mixed out.
///
/// When mixing between animations that key the same property, if a lower track also keys that property then the value will
/// briefly dip toward the lower track value during the mix. This happens because the first animation mixes from 100% to 0%
/// while the second animation mixes from 0% to 100%. Setting holdPrevious to true applies the first animation
/// at 100% during the mix so the lower track value is overwritten. Such dipping does not occur on the lowest track which
/// keys the property, only when a higher track also keys the property.
///
/// Snapping will occur if holdPrevious is true and this animation does not key all the same properties as the
/// previous animation.
bool getHoldPrevious();
void setHoldPrevious(bool inValue);
/// Seconds to postpone playing the animation. When a track entry is the current track entry, delay postpones incrementing
/// the track time. When a track entry is queued, delay is the time from the start of the previous animation to when the
/// track entry will become the current track entry.
float getDelay();
void setDelay(float inValue);
/// Current time in seconds this track entry has been the current track entry. The track time determines
/// TrackEntry.AnimationTime. The track time can be set to start the animation at a time other than 0, without affecting looping.
float getTrackTime();
void setTrackTime(float inValue);
/// The track time in seconds when this animation will be removed from the track. Defaults to the animation duration for
/// non-looping animations and to int.MaxValue for looping animations. If the track end time is reached and no
/// other animations are queued for playback, and mixing from any previous animations is complete, properties keyed by the animation,
/// are set to the setup pose and the track is cleared.
///
/// It may be desired to use AnimationState.addEmptyAnimation(int, float, float) to mix the properties back to the
/// setup pose over time, rather than have it happen instantly.
float getTrackEnd();
void setTrackEnd(float inValue);
/// Seconds when this animation starts, both initially and after looping. Defaults to 0.
///
/// When changing the animation start time, it often makes sense to set TrackEntry.AnimationLast to the same value to
/// prevent timeline keys before the start time from triggering.
float getAnimationStart();
void setAnimationStart(float inValue);
/// Seconds for the last frame of this animation. Non-looping animations won't play past this time. Looping animations will
/// loop back to TrackEntry.AnimationStart at this time. Defaults to the animation duration.
float getAnimationEnd();
void setAnimationEnd(float inValue);
/// The time in seconds this animation was last applied. Some timelines use this for one-time triggers. Eg, when this
/// animation is applied, event timelines will fire all events between the animation last time (exclusive) and animation time
/// (inclusive). Defaults to -1 to ensure triggers on frame 0 happen the first time this animation is applied.
float getAnimationLast();
void setAnimationLast(float inValue);
/// Uses TrackEntry.TrackTime to compute the animation time between TrackEntry.AnimationStart. and
/// TrackEntry.AnimationEnd. When the track time is 0, the animation time is equal to the animation start time.
float getAnimationTime();
/// Multiplier for the delta time when the animation state is updated, causing time for this animation to play slower or
/// faster. Defaults to 1.
float getTimeScale();
void setTimeScale(float inValue);
/// Values less than 1 mix this animation with the last skeleton pose. Defaults to 1, which overwrites the last skeleton pose with
/// this animation.
///
/// Typically track 0 is used to completely pose the skeleton, then alpha can be used on higher tracks. It doesn't make sense
/// to use alpha on track 0 if the skeleton pose is from the last frame render.
float getAlpha();
void setAlpha(float inValue);
///
/// When the mix percentage (mix time / mix duration) is less than the event threshold, event timelines for the animation
/// being mixed out will be applied. Defaults to 0, so event timelines are not applied for an animation being mixed out.
float getEventThreshold();
void setEventThreshold(float inValue);
/// When the mix percentage (mix time / mix duration) is less than the attachment threshold, attachment timelines for the
/// animation being mixed out will be applied. Defaults to 0, so attachment timelines are not applied for an animation being
/// mixed out.
float getAttachmentThreshold();
void setAttachmentThreshold(float inValue);
/// When the mix percentage (mix time / mix duration) is less than the draw order threshold, draw order timelines for the
/// animation being mixed out will be applied. Defaults to 0, so draw order timelines are not applied for an animation being
/// mixed out.
float getDrawOrderThreshold();
void setDrawOrderThreshold(float inValue);
/// The animation queued to start after this animation, or NULL.
TrackEntry* getNext();
/// Returns true if at least one loop has been completed.
bool isComplete();
/// Seconds from 0 to the mix duration when mixing from the previous animation to this animation. May be slightly more than
/// TrackEntry.MixDuration when the mix is complete.
float getMixTime();
void setMixTime(float inValue);
/// Seconds for mixing from the previous animation to this animation. Defaults to the value provided by
/// AnimationStateData based on the animation before this animation (if any).
///
/// The mix duration can be set manually rather than use the value from AnimationStateData.GetMix.
/// In that case, the mixDuration must be set before AnimationState.update(float) is next called.
///
/// When using AnimationState::addAnimation(int, Animation, bool, float) with a delay
/// less than or equal to 0, note the Delay is set using the mix duration from the AnimationStateData
float getMixDuration();
void setMixDuration(float inValue);
MixBlend getMixBlend();
void setMixBlend(MixBlend blend);
/// The track entry for the previous animation when mixing from the previous animation to this animation, or NULL if no
/// mixing is currently occuring. When mixing from multiple animations, MixingFrom makes up a double linked list with MixingTo.
TrackEntry* getMixingFrom();
/// The track entry for the next animation when mixing from this animation, or NULL if no mixing is currently occuring.
/// When mixing from multiple animations, MixingTo makes up a double linked list with MixingFrom.
TrackEntry* getMixingTo();
/// Resets the rotation directions for mixing this entry's rotate timelines. This can be useful to avoid bones rotating the
/// long way around when using alpha and starting animations on other tracks.
///
/// Mixing involves finding a rotation between two others, which has two possible solutions: the short way or the long way around.
/// The two rotations likely change over time, so which direction is the short or long way also changes.
/// If the short way was always chosen, bones would flip to the other side when that direction became the long way.
/// TrackEntry chooses the short way the first time it is applied and remembers that direction.
void resetRotationDirections();
void setListener(AnimationStateListener listener);
void setListener(AnimationStateListenerObject* listener);
private:
Animation* _animation;
TrackEntry* _next;
TrackEntry* _mixingFrom;
TrackEntry* _mixingTo;
int _trackIndex;
bool _loop, _holdPrevious;
float _eventThreshold, _attachmentThreshold, _drawOrderThreshold;
float _animationStart, _animationEnd, _animationLast, _nextAnimationLast;
float _delay, _trackTime, _trackLast, _nextTrackLast, _trackEnd, _timeScale;
float _alpha, _mixTime, _mixDuration, _interruptAlpha, _totalAlpha;
MixBlend _mixBlend;
Vector<int> _timelineMode;
Vector<TrackEntry*> _timelineHoldMix;
Vector<float> _timelinesRotation;
AnimationStateListener _listener;
AnimationStateListenerObject* _listenerObject;
void reset();
};
class SP_API EventQueueEntry : public SpineObject {
friend class EventQueue;
public:
EventType _type;
TrackEntry* _entry;
Event* _event;
EventQueueEntry(EventType eventType, TrackEntry* trackEntry, Event* event = NULL);
};
class SP_API EventQueue : public SpineObject {
friend class AnimationState;
private:
Vector<EventQueueEntry> _eventQueueEntries;
AnimationState& _state;
Pool<TrackEntry>& _trackEntryPool;
bool _drainDisabled;
static EventQueue* newEventQueue(AnimationState& state, Pool<TrackEntry>& trackEntryPool);
static EventQueueEntry newEventQueueEntry(EventType eventType, TrackEntry* entry, Event* event = NULL);
EventQueue(AnimationState& state, Pool<TrackEntry>& trackEntryPool);
~EventQueue();
void start(TrackEntry* entry);
void interrupt(TrackEntry* entry);
void end(TrackEntry* entry);
void dispose(TrackEntry* entry);
void complete(TrackEntry* entry);
void event(TrackEntry* entry, Event* event);
/// Raises all events in the queue and drains the queue.
void drain();
};
class SP_API AnimationState : public SpineObject, public HasRendererObject {
friend class TrackEntry;
friend class EventQueue;
public:
explicit AnimationState(AnimationStateData* data);
~AnimationState();
/// Increments the track entry times, setting queued animations as current if needed
/// @param delta delta time
void update(float delta);
/// Poses the skeleton using the track entry animations. There are no side effects other than invoking listeners, so the
/// animation state can be applied to multiple skeletons to pose them identically.
bool apply(Skeleton& skeleton);
/// Removes all animations from all tracks, leaving skeletons in their previous pose.
/// It may be desired to use AnimationState.setEmptyAnimations(float) to mix the skeletons back to the setup pose,
/// rather than leaving them in their previous pose.
void clearTracks();
/// Removes all animations from the tracks, leaving skeletons in their previous pose.
/// It may be desired to use AnimationState.setEmptyAnimations(float) to mix the skeletons back to the setup pose,
/// rather than leaving them in their previous pose.
void clearTrack(size_t trackIndex);
/// Sets an animation by name. setAnimation(int, Animation, bool)
TrackEntry* setAnimation(size_t trackIndex, const String& animationName, bool loop);
/// Sets the current animation for a track, discarding any queued animations.
/// @param loop If true, the animation will repeat.
/// If false, it will not, instead its last frame is applied if played beyond its duration.
/// In either case TrackEntry.TrackEnd determines when the track is cleared.
/// @return
/// A track entry to allow further customization of animation playback. References to the track entry must not be kept
/// after AnimationState.Dispose.
TrackEntry* setAnimation(size_t trackIndex, Animation* animation, bool loop);
/// Queues an animation by name.
/// addAnimation(int, Animation, bool, float)
TrackEntry* addAnimation(size_t trackIndex, const String& animationName, bool loop, float delay);
/// Adds an animation to be played delay seconds after the current or last queued animation
/// for a track. If the track is empty, it is equivalent to calling setAnimation.
/// @param delay
/// Seconds to begin this animation after the start of the previous animation. May be &lt;= 0 to use the animation
/// duration of the previous track minus any mix duration plus the negative delay.
///
/// @return A track entry to allow further customization of animation playback. References to the track entry must not be kept
/// after AnimationState.Dispose
TrackEntry* addAnimation(size_t trackIndex, Animation* animation, bool loop, float delay);
/// Sets an empty animation for a track, discarding any queued animations, and mixes to it over the specified mix duration.
TrackEntry* setEmptyAnimation(size_t trackIndex, float mixDuration);
/// Adds an empty animation to be played after the current or last queued animation for a track, and mixes to it over the
/// specified mix duration.
/// @return
/// A track entry to allow further customization of animation playback. References to the track entry must not be kept after AnimationState.Dispose.
///
/// @param trackIndex Track number.
/// @param mixDuration Mix duration.
/// @param delay Seconds to begin this animation after the start of the previous animation. May be &lt;= 0 to use the animation
/// duration of the previous track minus any mix duration plus the negative delay.
TrackEntry* addEmptyAnimation(size_t trackIndex, float mixDuration, float delay);
/// Sets an empty animation for every track, discarding any queued animations, and mixes to it over the specified mix duration.
void setEmptyAnimations(float mixDuration);
/// @return The track entry for the animation currently playing on the track, or NULL if no animation is currently playing.
TrackEntry* getCurrent(size_t trackIndex);
AnimationStateData* getData();
/// A list of tracks that have animations, which may contain NULLs.
Vector<TrackEntry*>& getTracks();
float getTimeScale();
void setTimeScale(float inValue);
void setListener(AnimationStateListener listener);
void setListener(AnimationStateListenerObject* listener);
void disableQueue();
void enableQueue();
private:
AnimationStateData* _data;
Pool<TrackEntry> _trackEntryPool;
Vector<TrackEntry*> _tracks;
Vector<Event*> _events;
EventQueue* _queue;
HashMap<int, bool> _propertyIDs;
bool _animationsChanged;
AnimationStateListener _listener;
AnimationStateListenerObject* _listenerObject;
float _timeScale;
static Animation* getEmptyAnimation();
static void applyRotateTimeline(RotateTimeline* rotateTimeline, Skeleton& skeleton, float time, float alpha, MixBlend pose, Vector<float>& timelinesRotation, size_t i, bool firstFrame);
/// Returns true when all mixing from entries are complete.
bool updateMixingFrom(TrackEntry* to, float delta);
float applyMixingFrom(TrackEntry* to, Skeleton& skeleton, MixBlend currentPose);
void queueEvents(TrackEntry* entry, float animationTime);
/// Sets the active TrackEntry for a given track number.
void setCurrent(size_t index, TrackEntry* current, bool interrupt);
TrackEntry* expandToIndex(size_t index);
/// Object-pooling version of new TrackEntry. Obtain an unused TrackEntry from the pool and clear/initialize its values.
/// @param last May be NULL.
TrackEntry* newTrackEntry(size_t trackIndex, Animation* animation, bool loop, TrackEntry* last);
/// Dispose all track entries queued after the given TrackEntry.
void disposeNext(TrackEntry* entry);
void animationsChanged();
void computeHold(TrackEntry* entry);
void computeNotLast(TrackEntry* entry);
};
} // namespace spine
#endif /* Spine_AnimationState_h */

View File

@@ -0,0 +1,85 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/Animation.h>
#include <spine/AnimationStateData.h>
#include <spine/SkeletonData.h>
using namespace spine;
AnimationStateData::AnimationStateData(SkeletonData *skeletonData) : _skeletonData(skeletonData), _defaultMix(0) {
}
void AnimationStateData::setMix(const String &fromName, const String &toName, float duration) {
Animation *from = _skeletonData->findAnimation(fromName);
Animation *to = _skeletonData->findAnimation(toName);
setMix(from, to, duration);
}
void AnimationStateData::setMix(Animation *from, Animation *to, float duration) {
assert(from != NULL);
assert(to != NULL);
AnimationPair key(from, to);
_animationToMixTime.put(key, duration);
}
float AnimationStateData::getMix(Animation *from, Animation *to) {
assert(from != NULL);
assert(to != NULL);
AnimationPair key(from, to);
if (_animationToMixTime.containsKey(key)) return _animationToMixTime[key];
return _defaultMix;
}
SkeletonData *AnimationStateData::getSkeletonData() {
return _skeletonData;
}
float AnimationStateData::getDefaultMix() {
return _defaultMix;
}
void AnimationStateData::setDefaultMix(float inValue) {
_defaultMix = inValue;
}
AnimationStateData::AnimationPair::AnimationPair(Animation *a1, Animation *a2) : _a1(a1), _a2(a2) {
}
bool AnimationStateData::AnimationPair::operator==(const AnimationPair &other) const {
return _a1->_name == other._a1->_name && _a2->_name == other._a2->_name;
}

View File

@@ -0,0 +1,85 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_AnimationStateData_h
#define Spine_AnimationStateData_h
#include <spine/HashMap.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
#include <assert.h>
namespace spine {
class SkeletonData;
class Animation;
/// Stores mix (crossfade) durations to be applied when AnimationState animations are changed.
class SP_API AnimationStateData : public SpineObject {
friend class AnimationState;
public:
explicit AnimationStateData(SkeletonData* skeletonData);
/// The SkeletonData to look up animations when they are specified by name.
SkeletonData* getSkeletonData();
/// The mix duration to use when no mix duration has been specifically defined between two animations.
float getDefaultMix();
void setDefaultMix(float inValue);
/// Sets a mix duration by animation names.
void setMix(const String& fromName, const String& toName, float duration);
/// Sets a mix duration when changing from the specified animation to the other.
/// See TrackEntry.MixDuration.
void setMix(Animation* from, Animation* to, float duration);
/// The mix duration to use when changing from the specified animation to the other,
/// or the DefaultMix if no mix duration has been set.
float getMix(Animation* from, Animation* to);
private:
class AnimationPair : public SpineObject {
public:
Animation* _a1;
Animation* _a2;
explicit AnimationPair(Animation* a1 = NULL, Animation* a2 = NULL);
bool operator==(const AnimationPair& other) const;
};
SkeletonData* _skeletonData;
float _defaultMix;
HashMap<AnimationPair, float> _animationToMixTime;
};
} // namespace spine
#endif /* Spine_AnimationStateData_h */

View File

@@ -0,0 +1,332 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/Atlas.h>
#include <spine/ContainerUtil.h>
#include <spine/TextureLoader.h>
#include <ctype.h>
using namespace spine;
Atlas::Atlas(const String &path, TextureLoader *textureLoader, bool createTexture) : _textureLoader(textureLoader) {
int dirLength;
char *dir;
int length;
const char *data;
/* Get directory from atlas path. */
const char *lastForwardSlash = strrchr(path.buffer(), '/');
const char *lastBackwardSlash = strrchr(path.buffer(), '\\');
const char *lastSlash = lastForwardSlash > lastBackwardSlash ? lastForwardSlash : lastBackwardSlash;
if (lastSlash == path) lastSlash++; /* Never drop starting slash. */
dirLength = (int)(lastSlash ? lastSlash - path.buffer() : 0);
dir = SpineExtension::calloc<char>(dirLength + 1, __FILE__, __LINE__);
memcpy(dir, path.buffer(), dirLength);
dir[dirLength] = '\0';
data = SpineExtension::readFile(path, &length);
if (data) {
load(data, length, dir, createTexture);
}
SpineExtension::free(data, __FILE__, __LINE__);
SpineExtension::free(dir, __FILE__, __LINE__);
}
Atlas::Atlas(const char *data, int length, const char *dir, TextureLoader *textureLoader, bool createTexture) : _textureLoader(
textureLoader) {
load(data, length, dir, createTexture);
}
Atlas::~Atlas() {
if (_textureLoader) {
for (size_t i = 0, n = _pages.size(); i < n; ++i) {
_textureLoader->unload(_pages[i]->getRendererObject());
}
}
ContainerUtil::cleanUpVectorOfPointers(_pages);
ContainerUtil::cleanUpVectorOfPointers(_regions);
}
void Atlas::flipV() {
for (size_t i = 0, n = _regions.size(); i < n; ++i) {
AtlasRegion *regionP = _regions[i];
AtlasRegion &region = *regionP;
region.v = 1 - region.v;
region.v2 = 1 - region.v2;
}
}
AtlasRegion *Atlas::findRegion(const String &name) {
for (size_t i = 0, n = _regions.size(); i < n; ++i)
if (_regions[i]->name == name) return _regions[i];
return NULL;
}
Vector<AtlasPage *> &Atlas::getPages() {
return _pages;
}
void Atlas::load(const char *begin, int length, const char *dir, bool createTexture) {
static const char *formatNames[] = {"", "Alpha", "Intensity", "LuminanceAlpha", "RGB565", "RGBA4444", "RGB888", "RGBA8888"};
static const char *textureFilterNames[] = {"", "Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest",
"MipMapNearestLinear", "MipMapLinearLinear"};
int count;
const char *end = begin + length;
int dirLength = (int)strlen(dir);
int needsSlash = dirLength > 0 && dir[dirLength - 1] != '/' && dir[dirLength - 1] != '\\';
AtlasPage *page = NULL;
Str str;
Str tuple[4];
while (readLine(&begin, end, &str)) {
if (str.end - str.begin == 0) {
page = 0;
} else if (!page) {
char *name = mallocString(&str);
char *path = SpineExtension::calloc<char>(dirLength + needsSlash + strlen(name) + 1, __FILE__, __LINE__);
memcpy(path, dir, dirLength);
if (needsSlash) path[dirLength] = '/';
strcpy(path + dirLength + needsSlash, name);
page = new (__FILE__, __LINE__) AtlasPage(String(name, true));
int tupleVal = readTuple(&begin, end, tuple);
assert(tupleVal == 2);
/* size is only optional for an atlas packed with an old TexturePacker. */
page->width = toInt(tuple);
page->height = toInt(tuple + 1);
readTuple(&begin, end, tuple);
page->format = (Format)indexOf(formatNames, 8, tuple);
readTuple(&begin, end, tuple);
page->minFilter = (TextureFilter)indexOf(textureFilterNames, 8, tuple);
page->magFilter = (TextureFilter)indexOf(textureFilterNames, 8, tuple + 1);
readValue(&begin, end, &str);
page->uWrap = TextureWrap_ClampToEdge;
page->vWrap = TextureWrap_ClampToEdge;
if (!equals(&str, "none")) {
if (str.end - str.begin == 1) {
if (*str.begin == 'x') {
page->uWrap = TextureWrap_Repeat;
} else if (*str.begin == 'y') {
page->vWrap = TextureWrap_Repeat;
}
} else if (equals(&str, "xy")) {
page->uWrap = TextureWrap_Repeat;
page->vWrap = TextureWrap_Repeat;
}
}
if (createTexture) {
if (_textureLoader) _textureLoader->load(*page, String(path));
SpineExtension::free(path, __FILE__, __LINE__);
} else
page->texturePath = String(path, true);
_pages.add(page);
} else {
AtlasRegion *region = new (__FILE__, __LINE__) AtlasRegion();
region->page = page;
region->name = String(mallocString(&str), true);
readValue(&begin, end, &str);
if (equals(&str, "true"))
region->degrees = 90;
else if (equals(&str, "false"))
region->degrees = 0;
else
region->degrees = toInt(&str);
region->rotate = region->degrees == 90;
readTuple(&begin, end, tuple);
region->x = toInt(tuple);
region->y = toInt(tuple + 1);
readTuple(&begin, end, tuple);
region->width = toInt(tuple);
region->height = toInt(tuple + 1);
region->u = region->x / (float)page->width;
region->v = region->y / (float)page->height;
if (region->rotate) {
region->u2 = (region->x + region->height) / (float)page->width;
region->v2 = (region->y + region->width) / (float)page->height;
} else {
region->u2 = (region->x + region->width) / (float)page->width;
region->v2 = (region->y + region->height) / (float)page->height;
}
count = readTuple(&begin, end, tuple);
assert(count);
if (count == 4) {
/* split is optional */
region->splits.setSize(4, 0);
region->splits[0] = toInt(tuple);
region->splits[1] = toInt(tuple + 1);
region->splits[2] = toInt(tuple + 2);
region->splits[3] = toInt(tuple + 3);
count = readTuple(&begin, end, tuple);
assert(count);
if (count == 4) {
/* pad is optional, but only present with splits */
region->pads.setSize(4, 0);
region->pads[0] = toInt(tuple);
region->pads[1] = toInt(tuple + 1);
region->pads[2] = toInt(tuple + 2);
region->pads[3] = toInt(tuple + 3);
readTuple(&begin, end, tuple);
}
}
region->originalWidth = toInt(tuple);
region->originalHeight = toInt(tuple + 1);
readTuple(&begin, end, tuple);
region->offsetX = (float)toInt(tuple);
region->offsetY = (float)toInt(tuple + 1);
readValue(&begin, end, &str);
region->index = toInt(&str);
_regions.add(region);
}
}
}
void Atlas::trim(Str *str) {
while (isspace((unsigned char)*str->begin) && str->begin < str->end)
(str->begin)++;
if (str->begin == str->end) return;
str->end--;
while (((unsigned char)*str->end == '\r') && str->end >= str->begin)
str->end--;
str->end++;
}
int Atlas::readLine(const char **begin, const char *end, Str *str) {
if (*begin == end) return 0;
str->begin = *begin;
/* Find next delimiter. */
while (*begin != end && **begin != '\n')
(*begin)++;
str->end = *begin;
trim(str);
if (*begin != end) (*begin)++;
return 1;
}
int Atlas::beginPast(Str *str, char c) {
const char *begin = str->begin;
while (true) {
char lastSkippedChar = *begin;
if (begin == str->end) return 0;
begin++;
if (lastSkippedChar == c) break;
}
str->begin = begin;
return 1;
}
int Atlas::readValue(const char **begin, const char *end, Str *str) {
readLine(begin, end, str);
if (!beginPast(str, ':')) return 0;
trim(str);
return 1;
}
int Atlas::readTuple(const char **begin, const char *end, Str tuple[]) {
int i;
Str str = {NULL, NULL};
readLine(begin, end, &str);
if (!beginPast(&str, ':')) return 0;
for (i = 0; i < 3; ++i) {
tuple[i].begin = str.begin;
if (!beginPast(&str, ',')) break;
tuple[i].end = str.begin - 2;
trim(&tuple[i]);
}
tuple[i].begin = str.begin;
tuple[i].end = str.end;
trim(&tuple[i]);
return i + 1;
}
char *Atlas::mallocString(Str *str) {
int length = (int)(str->end - str->begin);
char *string = SpineExtension::calloc<char>(length + 1, __FILE__, __LINE__);
memcpy(string, str->begin, length);
string[length] = '\0';
return string;
}
int Atlas::indexOf(const char **array, int count, Str *str) {
int length = (int)(str->end - str->begin);
int i;
for (i = count - 1; i >= 0; i--)
if (strncmp(array[i], str->begin, length) == 0) return i;
return 0;
}
int Atlas::equals(Str *str, const char *other) {
return strncmp(other, str->begin, str->end - str->begin) == 0;
}
int Atlas::toInt(Str *str) {
return (int)strtol(str->begin, (char **)&str->end, 10);
}

View File

@@ -0,0 +1,155 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_Atlas_h
#define Spine_Atlas_h
#include <spine/Extension.h>
#include <spine/HasRendererObject.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
#include <spine/Vector.h>
namespace spine {
enum Format {
Format_Alpha,
Format_Intensity,
Format_LuminanceAlpha,
Format_RGB565,
Format_RGBA4444,
Format_RGB888,
Format_RGBA8888
};
enum TextureFilter {
TextureFilter_Unknown,
TextureFilter_Nearest,
TextureFilter_Linear,
TextureFilter_MipMap,
TextureFilter_MipMapNearestNearest,
TextureFilter_MipMapLinearNearest,
TextureFilter_MipMapNearestLinear,
TextureFilter_MipMapLinearLinear
};
enum TextureWrap {
TextureWrap_MirroredRepeat,
TextureWrap_ClampToEdge,
TextureWrap_Repeat
};
class SP_API AtlasPage : public SpineObject, public HasRendererObject {
public:
String name;
String texturePath;
Format format;
TextureFilter minFilter;
TextureFilter magFilter;
TextureWrap uWrap;
TextureWrap vWrap;
int width, height;
explicit AtlasPage(const String &inName) : name(inName), format(Format_RGBA8888), minFilter(TextureFilter_Nearest), magFilter(TextureFilter_Nearest), uWrap(TextureWrap_ClampToEdge), vWrap(TextureWrap_ClampToEdge), width(0), height(0) {
}
};
class SP_API AtlasRegion : public SpineObject {
public:
AtlasPage *page;
String name;
int x, y, width, height;
float u, v, u2, v2;
float offsetX, offsetY;
int originalWidth, originalHeight;
int index;
bool rotate;
int degrees;
Vector<int> splits;
Vector<int> pads;
};
class TextureLoader;
class SP_API Atlas : public SpineObject {
public:
Atlas(const String &path, TextureLoader *textureLoader, bool createTexture = true);
Atlas(const char *data, int length, const char *dir, TextureLoader *textureLoader, bool createTexture = true);
~Atlas();
void flipV();
/// Returns the first region found with the specified name. This method uses String comparison to find the region, so the result
/// should be cached rather than calling this method multiple times.
/// @return The region, or NULL.
AtlasRegion *findRegion(const String &name);
Vector<AtlasPage *> &getPages();
private:
Vector<AtlasPage *> _pages;
Vector<AtlasRegion *> _regions;
TextureLoader *_textureLoader;
void load(const char *begin, int length, const char *dir, bool createTexture);
class Str {
public:
const char *begin;
const char *end;
};
static void trim(Str *str);
/// Tokenize string without modification. Returns 0 on failure
static int readLine(const char **begin, const char *end, Str *str);
/// Moves str->begin past the first occurence of c. Returns 0 on failure
static int beginPast(Str *str, char c);
/// Returns 0 on failure
static int readValue(const char **begin, const char *end, Str *str);
/// Returns the number of tuple values read (1, 2, 4, or 0 for failure)
static int readTuple(const char **begin, const char *end, Str tuple[]);
static char *mallocString(Str *str);
static int indexOf(const char **array, int count, Str *str);
static int equals(Str *str, const char *other);
static int toInt(Str *str);
static Atlas *abortAtlas(Atlas *atlas);
};
} // namespace spine
#endif /* Spine_Atlas_h */

View File

@@ -0,0 +1,129 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/AtlasAttachmentLoader.h>
#include <spine/BoundingBoxAttachment.h>
#include <spine/ClippingAttachment.h>
#include <spine/MeshAttachment.h>
#include <spine/PathAttachment.h>
#include <spine/PointAttachment.h>
#include <spine/RegionAttachment.h>
#include <spine/Skin.h>
#include <spine/Atlas.h>
namespace spine {
RTTI_IMPL(AtlasAttachmentLoader, AttachmentLoader)
AtlasAttachmentLoader::AtlasAttachmentLoader(Atlas *atlas) : AttachmentLoader(), _atlas(atlas) {
}
RegionAttachment *AtlasAttachmentLoader::newRegionAttachment(Skin &skin, const String &name, const String &path) {
SP_UNUSED(skin);
AtlasRegion *regionP = findRegion(path);
if (!regionP) return NULL;
AtlasRegion &region = *regionP;
RegionAttachment *attachmentP = new (__FILE__, __LINE__) RegionAttachment(name);
RegionAttachment &attachment = *attachmentP;
attachment.setRendererObject(regionP);
attachment.setUVs(region.u, region.v, region.u2, region.v2, region.rotate);
attachment._regionOffsetX = region.offsetX;
attachment._regionOffsetY = region.offsetY;
attachment._regionWidth = (float)region.width;
attachment._regionHeight = (float)region.height;
attachment._regionOriginalWidth = (float)region.originalWidth;
attachment._regionOriginalHeight = (float)region.originalHeight;
return attachmentP;
}
MeshAttachment *AtlasAttachmentLoader::newMeshAttachment(Skin &skin, const String &name, const String &path) {
SP_UNUSED(skin);
AtlasRegion *regionP = findRegion(path);
if (!regionP) return NULL;
AtlasRegion &region = *regionP;
MeshAttachment *attachmentP = new (__FILE__, __LINE__) MeshAttachment(name);
MeshAttachment &attachment = *attachmentP;
attachment.setRendererObject(regionP);
attachment._regionU = region.u;
attachment._regionV = region.v;
attachment._regionU2 = region.u2;
attachment._regionV2 = region.v2;
attachment._regionRotate = region.rotate;
attachment._regionDegrees = region.degrees;
attachment._regionOffsetX = region.offsetX;
attachment._regionOffsetY = region.offsetY;
attachment._regionWidth = (float)region.width;
attachment._regionHeight = (float)region.height;
attachment._regionOriginalWidth = (float)region.originalWidth;
attachment._regionOriginalHeight = (float)region.originalHeight;
return attachmentP;
}
BoundingBoxAttachment *AtlasAttachmentLoader::newBoundingBoxAttachment(Skin &skin, const String &name) {
SP_UNUSED(skin);
return new (__FILE__, __LINE__) BoundingBoxAttachment(name);
}
PathAttachment *AtlasAttachmentLoader::newPathAttachment(Skin &skin, const String &name) {
SP_UNUSED(skin);
return new (__FILE__, __LINE__) PathAttachment(name);
}
PointAttachment *AtlasAttachmentLoader::newPointAttachment(Skin &skin, const String &name) {
SP_UNUSED(skin);
return new (__FILE__, __LINE__) PointAttachment(name);
}
ClippingAttachment *AtlasAttachmentLoader::newClippingAttachment(Skin &skin, const String &name) {
SP_UNUSED(skin);
return new (__FILE__, __LINE__) ClippingAttachment(name);
}
void AtlasAttachmentLoader::configureAttachment(Attachment *attachment) {
SP_UNUSED(attachment);
}
AtlasRegion *AtlasAttachmentLoader::findRegion(const String &name) {
return _atlas->findRegion(name);
}
} // namespace spine

View File

@@ -0,0 +1,70 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_AtlasAttachmentLoader_h
#define Spine_AtlasAttachmentLoader_h
#include <spine/AttachmentLoader.h>
#include <spine/SpineString.h>
#include <spine/Vector.h>
namespace spine {
class Atlas;
class AtlasRegion;
/// An AttachmentLoader that configures attachments using texture regions from an Atlas.
/// See http://esotericsoftware.com/spine-loading-skeleton-data#JSON-and-binary-data about Loading Skeleton Data in the Spine Runtimes Guide.
class SP_API AtlasAttachmentLoader : public AttachmentLoader {
public:
RTTI_DECL
explicit AtlasAttachmentLoader(Atlas* atlas);
virtual RegionAttachment* newRegionAttachment(Skin& skin, const String& name, const String& path);
virtual MeshAttachment* newMeshAttachment(Skin& skin, const String& name, const String& path);
virtual BoundingBoxAttachment* newBoundingBoxAttachment(Skin& skin, const String& name);
virtual PathAttachment* newPathAttachment(Skin& skin, const String& name);
virtual PointAttachment* newPointAttachment(Skin& skin, const String& name);
virtual ClippingAttachment* newClippingAttachment(Skin& skin, const String& name);
virtual void configureAttachment(Attachment* attachment);
AtlasRegion* findRegion(const String& name);
private:
Atlas* _atlas;
};
} // namespace spine
#endif /* Spine_AtlasAttachmentLoader_h */

View File

@@ -0,0 +1,63 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/Attachment.h>
#include <assert.h>
using namespace spine;
RTTI_IMPL_NOPARENT(Attachment)
Attachment::Attachment(const String &name) : _name(name), _refCount(0) {
assert(_name.length() > 0);
}
Attachment::~Attachment() {
}
const String &Attachment::getName() const {
return _name;
}
int Attachment::getRefCount() {
return _refCount;
}
void Attachment::reference() {
_refCount++;
}
void Attachment::dereference() {
_refCount--;
}

View File

@@ -0,0 +1,60 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_Attachment_h
#define Spine_Attachment_h
#include <spine/RTTI.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
namespace spine {
class SP_API Attachment : public SpineObject {
RTTI_DECL
public:
explicit Attachment(const String &name);
virtual ~Attachment();
const String &getName() const;
virtual Attachment *copy() = 0;
int getRefCount();
void reference();
void dereference();
private:
const String _name;
int _refCount;
};
} // namespace spine
#endif /* Spine_Attachment_h */

View File

@@ -0,0 +1,52 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/AttachmentLoader.h>
#include <spine/BoundingBoxAttachment.h>
#include <spine/ClippingAttachment.h>
#include <spine/MeshAttachment.h>
#include <spine/PathAttachment.h>
#include <spine/PointAttachment.h>
#include <spine/RegionAttachment.h>
#include <spine/Skin.h>
using namespace spine;
RTTI_IMPL_NOPARENT(AttachmentLoader)
AttachmentLoader::AttachmentLoader() {
}
AttachmentLoader::~AttachmentLoader() {
}

View File

@@ -0,0 +1,75 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_AttachmentLoader_h
#define Spine_AttachmentLoader_h
#include <spine/RTTI.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
namespace spine {
class Skin;
class Attachment;
class RegionAttachment;
class MeshAttachment;
class BoundingBoxAttachment;
class PathAttachment;
class PointAttachment;
class ClippingAttachment;
class SP_API AttachmentLoader : public SpineObject {
public:
RTTI_DECL
AttachmentLoader();
virtual ~AttachmentLoader();
/// @return May be NULL to not load any attachment.
virtual RegionAttachment* newRegionAttachment(Skin& skin, const String& name, const String& path) = 0;
/// @return May be NULL to not load any attachment.
virtual MeshAttachment* newMeshAttachment(Skin& skin, const String& name, const String& path) = 0;
/// @return May be NULL to not load any attachment.
virtual BoundingBoxAttachment* newBoundingBoxAttachment(Skin& skin, const String& name) = 0;
/// @return May be NULL to not load any attachment
virtual PathAttachment* newPathAttachment(Skin& skin, const String& name) = 0;
virtual PointAttachment* newPointAttachment(Skin& skin, const String& name) = 0;
virtual ClippingAttachment* newClippingAttachment(Skin& skin, const String& name) = 0;
virtual void configureAttachment(Attachment* attachment) = 0;
};
} // namespace spine
#endif /* Spine_AttachmentLoader_h */

View File

@@ -0,0 +1,127 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/AttachmentTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/Bone.h>
#include <spine/Slot.h>
#include <spine/SlotData.h>
#include <spine/TimelineType.h>
using namespace spine;
RTTI_IMPL(AttachmentTimeline, Timeline)
AttachmentTimeline::AttachmentTimeline(int frameCount) : Timeline(), _slotIndex(0) {
_frames.ensureCapacity(frameCount);
_attachmentNames.ensureCapacity(frameCount);
_frames.setSize(frameCount, 0);
for (int i = 0; i < frameCount; ++i) {
_attachmentNames.add(String());
}
}
void AttachmentTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
SP_UNUSED(alpha);
assert(_slotIndex < skeleton._slots.size());
String *attachmentName;
Slot *slotP = skeleton._slots[_slotIndex];
Slot &slot = *slotP;
if (!slot._bone.isActive()) return;
if (direction == MixDirection_Out && blend == MixBlend_Setup) {
attachmentName = &slot._data._attachmentName;
slot.setAttachment(attachmentName->length() == 0 ? NULL : skeleton.getAttachment(_slotIndex, *attachmentName));
return;
}
if (time < _frames[0]) {
// Time is before first frame.
if (blend == MixBlend_Setup || blend == MixBlend_First) {
attachmentName = &slot._data._attachmentName;
slot.setAttachment(attachmentName->length() == 0 ? NULL : skeleton.getAttachment(_slotIndex, *attachmentName));
}
return;
}
size_t frameIndex;
if (time >= _frames[_frames.size() - 1]) {
// Time is after last frame.
frameIndex = _frames.size() - 1;
} else {
frameIndex = Animation::binarySearch(_frames, time, 1) - 1;
}
attachmentName = &_attachmentNames[frameIndex];
slot.setAttachment(attachmentName->length() == 0 ? NULL : skeleton.getAttachment(_slotIndex, *attachmentName));
}
int AttachmentTimeline::getPropertyId() {
return ((int)TimelineType_Attachment << 24) + _slotIndex;
}
void AttachmentTimeline::setFrame(int frameIndex, float time, const String &attachmentName) {
_frames[frameIndex] = time;
_attachmentNames[frameIndex] = attachmentName;
}
size_t AttachmentTimeline::getSlotIndex() {
return _slotIndex;
}
void AttachmentTimeline::setSlotIndex(size_t inValue) {
_slotIndex = inValue;
}
const Vector<float> &AttachmentTimeline::getFrames() {
return _frames;
}
const Vector<String> &AttachmentTimeline::getAttachmentNames() {
return _attachmentNames;
}
size_t AttachmentTimeline::getFrameCount() {
return _frames.size();
}

View File

@@ -0,0 +1,74 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_AttachmentTimeline_h
#define Spine_AttachmentTimeline_h
#include <spine/MixBlend.h>
#include <spine/MixDirection.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
#include <spine/Timeline.h>
#include <spine/Vector.h>
namespace spine {
class Skeleton;
class Event;
class SP_API AttachmentTimeline : public Timeline {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
explicit AttachmentTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixBlend blend, MixDirection direction);
virtual int getPropertyId();
/// Sets the time and value of the specified keyframe.
void setFrame(int frameIndex, float time, const String& attachmentName);
size_t getSlotIndex();
void setSlotIndex(size_t inValue);
const Vector<float>& getFrames();
const Vector<String>& getAttachmentNames();
size_t getFrameCount();
private:
size_t _slotIndex;
Vector<float> _frames;
Vector<String> _attachmentNames;
};
} // namespace spine
#endif /* Spine_AttachmentTimeline_h */

View File

@@ -0,0 +1,45 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_AttachmentType_h
#define Spine_AttachmentType_h
namespace spine {
enum AttachmentType {
AttachmentType_Region,
AttachmentType_Boundingbox,
AttachmentType_Mesh,
AttachmentType_Linkedmesh,
AttachmentType_Path,
AttachmentType_Point,
AttachmentType_Clipping
};
}
#endif /* Spine_AttachmentType_h */

View File

@@ -0,0 +1,42 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_BlendMode_h
#define Spine_BlendMode_h
namespace spine {
enum BlendMode {
BlendMode_Normal = 0,
BlendMode_Additive,
BlendMode_Multiply,
BlendMode_Screen
};
}
#endif /* Spine_BlendMode_h */

View File

@@ -0,0 +1,547 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/Bone.h>
#include <spine/BoneData.h>
#include <spine/Skeleton.h>
using namespace spine;
RTTI_IMPL(Bone, Updatable)
bool Bone::yDown = false;
void Bone::setYDown(bool inValue) {
yDown = inValue;
}
bool Bone::isYDown() {
return yDown;
}
Bone::Bone(BoneData &data, Skeleton &skeleton, Bone *parent) : Updatable(),
_data(data),
_skeleton(skeleton),
_parent(parent),
_x(0),
_y(0),
_rotation(0),
_scaleX(0),
_scaleY(0),
_shearX(0),
_shearY(0),
_ax(0),
_ay(0),
_arotation(0),
_ascaleX(0),
_ascaleY(0),
_ashearX(0),
_ashearY(0),
_appliedValid(false),
_a(1),
_b(0),
_worldX(0),
_c(0),
_d(1),
_worldY(0),
_sorted(false),
_active(false) {
setToSetupPose();
}
void Bone::update() {
updateWorldTransform(_x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY);
}
void Bone::updateWorldTransform() {
updateWorldTransform(_x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY);
}
void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY) {
float cosine, sine;
float pa, pb, pc, pd;
Bone *parent = _parent;
_ax = x;
_ay = y;
_arotation = rotation;
_ascaleX = scaleX;
_ascaleY = scaleY;
_ashearX = shearX;
_ashearY = shearY;
_appliedValid = true;
if (!parent) { /* Root bone. */
float rotationY = rotation + 90 + shearY;
float sx = _skeleton.getScaleX();
float sy = _skeleton.getScaleY();
_a = MathUtil::cosDeg(rotation + shearX) * scaleX * sx;
_b = MathUtil::cosDeg(rotationY) * scaleY * sx;
_c = MathUtil::sinDeg(rotation + shearX) * scaleX * sy;
_d = MathUtil::sinDeg(rotationY) * scaleY * sy;
_worldX = x * sx + _skeleton.getX();
_worldY = y * sy + _skeleton.getY();
return;
}
pa = parent->_a;
pb = parent->_b;
pc = parent->_c;
pd = parent->_d;
_worldX = pa * x + pb * y + parent->_worldX;
_worldY = pc * x + pd * y + parent->_worldY;
switch (_data.getTransformMode()) {
case TransformMode_Normal: {
float rotationY = rotation + 90 + shearY;
float la = MathUtil::cosDeg(rotation + shearX) * scaleX;
float lb = MathUtil::cosDeg(rotationY) * scaleY;
float lc = MathUtil::sinDeg(rotation + shearX) * scaleX;
float ld = MathUtil::sinDeg(rotationY) * scaleY;
_a = pa * la + pb * lc;
_b = pa * lb + pb * ld;
_c = pc * la + pd * lc;
_d = pc * lb + pd * ld;
return;
}
case TransformMode_OnlyTranslation: {
float rotationY = rotation + 90 + shearY;
_a = MathUtil::cosDeg(rotation + shearX) * scaleX;
_b = MathUtil::cosDeg(rotationY) * scaleY;
_c = MathUtil::sinDeg(rotation + shearX) * scaleX;
_d = MathUtil::sinDeg(rotationY) * scaleY;
break;
}
case TransformMode_NoRotationOrReflection: {
float s = pa * pa + pc * pc;
float prx, rx, ry, la, lb, lc, ld;
if (s > 0.0001f) {
s = MathUtil::abs(pa * pd - pb * pc) / s;
pb = pc * s;
pd = pa * s;
prx = MathUtil::atan2(pc, pa) * MathUtil::Rad_Deg;
} else {
pa = 0;
pc = 0;
prx = 90 - MathUtil::atan2(pd, pb) * MathUtil::Rad_Deg;
}
rx = rotation + shearX - prx;
ry = rotation + shearY - prx + 90;
la = MathUtil::cosDeg(rx) * scaleX;
lb = MathUtil::cosDeg(ry) * scaleY;
lc = MathUtil::sinDeg(rx) * scaleX;
ld = MathUtil::sinDeg(ry) * scaleY;
_a = pa * la - pb * lc;
_b = pa * lb - pb * ld;
_c = pc * la + pd * lc;
_d = pc * lb + pd * ld;
break;
}
case TransformMode_NoScale:
case TransformMode_NoScaleOrReflection: {
float za, zc, s;
float r, zb, zd, la, lb, lc, ld;
cosine = MathUtil::cosDeg(rotation);
sine = MathUtil::sinDeg(rotation);
za = (pa * cosine + pb * sine) / _skeleton.getScaleX();
zc = (pc * cosine + pd * sine) / _skeleton.getScaleY();
s = MathUtil::sqrt(za * za + zc * zc);
if (s > 0.00001f) s = 1 / s;
za *= s;
zc *= s;
s = MathUtil::sqrt(za * za + zc * zc);
if (_data.getTransformMode() == TransformMode_NoScale && (pa * pd - pb * pc < 0) != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0))
s = -s;
r = MathUtil::Pi / 2 + MathUtil::atan2(zc, za);
zb = MathUtil::cos(r) * s;
zd = MathUtil::sin(r) * s;
la = MathUtil::cosDeg(shearX) * scaleX;
lb = MathUtil::cosDeg(90 + shearY) * scaleY;
lc = MathUtil::sinDeg(shearX) * scaleX;
ld = MathUtil::sinDeg(90 + shearY) * scaleY;
_a = za * la + zb * lc;
_b = za * lb + zb * ld;
_c = zc * la + zd * lc;
_d = zc * lb + zd * ld;
break;
}
}
_a *= _skeleton.getScaleX();
_b *= _skeleton.getScaleX();
_c *= _skeleton.getScaleY();
_d *= _skeleton.getScaleY();
}
void Bone::setToSetupPose() {
BoneData &data = _data;
_x = data.getX();
_y = data.getY();
_rotation = data.getRotation();
_scaleX = data.getScaleX();
_scaleY = data.getScaleY();
_shearX = data.getShearX();
_shearY = data.getShearY();
}
void Bone::worldToLocal(float worldX, float worldY, float &outLocalX, float &outLocalY) {
float a = _a;
float b = _b;
float c = _c;
float d = _d;
float invDet = 1 / (a * d - b * c);
float x = worldX - _worldX;
float y = worldY - _worldY;
outLocalX = (x * d * invDet - y * b * invDet);
outLocalY = (y * a * invDet - x * c * invDet);
}
void Bone::localToWorld(float localX, float localY, float &outWorldX, float &outWorldY) {
outWorldX = localX * _a + localY * _b + _worldX;
outWorldY = localX * _c + localY * _d + _worldY;
}
float Bone::worldToLocalRotation(float worldRotation) {
float sin = MathUtil::sinDeg(worldRotation);
float cos = MathUtil::cosDeg(worldRotation);
return MathUtil::atan2(_a * sin - _c * cos, _d * cos - _b * sin) * MathUtil::Rad_Deg + this->_rotation - this->_shearX;
}
float Bone::localToWorldRotation(float localRotation) {
localRotation -= this->_rotation - this->_shearX;
float sin = MathUtil::sinDeg(localRotation);
float cos = MathUtil::cosDeg(localRotation);
return MathUtil::atan2(cos * _c + sin * _d, cos * _a + sin * _b) * MathUtil::Rad_Deg;
}
void Bone::rotateWorld(float degrees) {
float a = _a;
float b = _b;
float c = _c;
float d = _d;
float cos = MathUtil::cosDeg(degrees);
float sin = MathUtil::sinDeg(degrees);
_a = cos * a - sin * c;
_b = cos * b - sin * d;
_c = sin * a + cos * c;
_d = sin * b + cos * d;
_appliedValid = false;
}
float Bone::getWorldToLocalRotationX() {
Bone *parent = _parent;
if (!parent) {
return _arotation;
}
float pa = parent->_a;
float pb = parent->_b;
float pc = parent->_c;
float pd = parent->_d;
float a = _a;
float c = _c;
return MathUtil::atan2(pa * c - pc * a, pd * a - pb * c) * MathUtil::Rad_Deg;
}
float Bone::getWorldToLocalRotationY() {
Bone *parent = _parent;
if (!parent) {
return _arotation;
}
float pa = parent->_a;
float pb = parent->_b;
float pc = parent->_c;
float pd = parent->_d;
float b = _b;
float d = _d;
return MathUtil::atan2(pa * d - pc * b, pd * b - pb * d) * MathUtil::Rad_Deg;
}
BoneData &Bone::getData() {
return _data;
}
Skeleton &Bone::getSkeleton() {
return _skeleton;
}
Bone *Bone::getParent() {
return _parent;
}
Vector<Bone *> &Bone::getChildren() {
return _children;
}
float Bone::getX() {
return _x;
}
void Bone::setX(float inValue) {
_x = inValue;
}
float Bone::getY() {
return _y;
}
void Bone::setY(float inValue) {
_y = inValue;
}
float Bone::getRotation() {
return _rotation;
}
void Bone::setRotation(float inValue) {
_rotation = inValue;
}
float Bone::getScaleX() {
return _scaleX;
}
void Bone::setScaleX(float inValue) {
_scaleX = inValue;
}
float Bone::getScaleY() {
return _scaleY;
}
void Bone::setScaleY(float inValue) {
_scaleY = inValue;
}
float Bone::getShearX() {
return _shearX;
}
void Bone::setShearX(float inValue) {
_shearX = inValue;
}
float Bone::getShearY() {
return _shearY;
}
void Bone::setShearY(float inValue) {
_shearY = inValue;
}
float Bone::getAppliedRotation() {
return _arotation;
}
void Bone::setAppliedRotation(float inValue) {
_arotation = inValue;
}
float Bone::getAX() {
return _ax;
}
void Bone::setAX(float inValue) {
_ax = inValue;
}
float Bone::getAY() {
return _ay;
}
void Bone::setAY(float inValue) {
_ay = inValue;
}
float Bone::getAScaleX() {
return _ascaleX;
}
void Bone::setAScaleX(float inValue) {
_ascaleX = inValue;
}
float Bone::getAScaleY() {
return _ascaleY;
}
void Bone::setAScaleY(float inValue) {
_ascaleY = inValue;
}
float Bone::getAShearX() {
return _ashearX;
}
void Bone::setAShearX(float inValue) {
_ashearX = inValue;
}
float Bone::getAShearY() {
return _ashearY;
}
void Bone::setAShearY(float inValue) {
_ashearY = inValue;
}
float Bone::getA() {
return _a;
}
void Bone::setA(float inValue) {
_a = inValue;
}
float Bone::getB() {
return _b;
}
void Bone::setB(float inValue) {
_b = inValue;
}
float Bone::getC() {
return _c;
}
void Bone::setC(float inValue) {
_c = inValue;
}
float Bone::getD() {
return _d;
}
void Bone::setD(float inValue) {
_d = inValue;
}
float Bone::getWorldX() {
return _worldX;
}
void Bone::setWorldX(float inValue) {
_worldX = inValue;
}
float Bone::getWorldY() {
return _worldY;
}
void Bone::setWorldY(float inValue) {
_worldY = inValue;
}
float Bone::getWorldRotationX() {
return MathUtil::atan2(_c, _a) * MathUtil::MathUtil::Rad_Deg;
}
float Bone::getWorldRotationY() {
return MathUtil::atan2(_d, _b) * MathUtil::Rad_Deg;
}
float Bone::getWorldScaleX() {
return MathUtil::sqrt(_a * _a + _c * _c);
}
float Bone::getWorldScaleY() {
return MathUtil::sqrt(_b * _b + _d * _d);
}
bool Bone::isAppliedValid() {
return _appliedValid;
}
void Bone::setAppliedValid(bool valid) {
_appliedValid = valid;
}
void Bone::updateAppliedTransform() {
Bone *parent = _parent;
_appliedValid = 1;
if (!parent) {
_ax = _worldX;
_ay = _worldY;
_arotation = MathUtil::atan2(_c, _a) * MathUtil::Rad_Deg;
_ascaleX = MathUtil::sqrt(_a * _a + _c * _c);
_ascaleY = MathUtil::sqrt(_b * _b + _d * _d);
_ashearX = 0;
_ashearY = MathUtil::atan2(_a * _b + _c * _d, _a * _d - _b * _c) * MathUtil::Rad_Deg;
} else {
float pa = parent->_a, pb = parent->_b, pc = parent->_c, pd = parent->_d;
float pid = 1 / (pa * pd - pb * pc);
float dx = _worldX - parent->_worldX, dy = _worldY - parent->_worldY;
float ia = pid * pd;
float id = pid * pa;
float ib = pid * pb;
float ic = pid * pc;
float ra = ia * _a - ib * _c;
float rb = ia * _b - ib * _d;
float rc = id * _c - ic * _a;
float rd = id * _d - ic * _b;
_ax = (dx * pd * pid - dy * pb * pid);
_ay = (dy * pa * pid - dx * pc * pid);
_ashearX = 0;
_ascaleX = MathUtil::sqrt(ra * ra + rc * rc);
if (_ascaleX > 0.0001f) {
float det = ra * rd - rb * rc;
_ascaleY = det / _ascaleX;
_ashearY = MathUtil::atan2(ra * rb + rc * rd, det) * MathUtil::Rad_Deg;
_arotation = MathUtil::atan2(rc, ra) * MathUtil::Rad_Deg;
} else {
_ascaleX = 0;
_ascaleY = MathUtil::sqrt(rb * rb + rd * rd);
_ashearY = 0;
_arotation = 90 - MathUtil::atan2(rd, rb) * MathUtil::Rad_Deg;
}
}
}
bool Bone::isActive() {
return _active;
}
void Bone::setActive(bool inValue) {
_active = inValue;
}

View File

@@ -0,0 +1,251 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_Bone_h
#define Spine_Bone_h
#include <spine/SpineObject.h>
#include <spine/Updatable.h>
#include <spine/Vector.h>
namespace spine {
class BoneData;
class Skeleton;
/// Stores a bone's current pose.
///
/// A bone has a local transform which is used to compute its world transform. A bone also has an applied transform, which is a
/// local transform that can be applied to compute the world transform. The local transform and applied transform may differ if a
/// constraint or application code modifies the world transform after it was computed from the local transform.
class SP_API Bone : public Updatable {
friend class AnimationState;
friend class RotateTimeline;
friend class IkConstraint;
friend class TransformConstraint;
friend class VertexAttachment;
friend class PathConstraint;
friend class Skeleton;
friend class RegionAttachment;
friend class PointAttachment;
friend class ScaleTimeline;
friend class ShearTimeline;
friend class TranslateTimeline;
RTTI_DECL
public:
static void setYDown(bool inValue);
static bool isYDown();
/// @param parent May be NULL.
Bone(BoneData &data, Skeleton &skeleton, Bone *parent = NULL);
/// Same as updateWorldTransform. This method exists for Bone to implement Spine::Updatable.
virtual void update();
/// Computes the world transform using the parent bone and this bone's local transform.
void updateWorldTransform();
/// Computes the world transform using the parent bone and the specified local transform.
void updateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY);
void setToSetupPose();
void worldToLocal(float worldX, float worldY, float &outLocalX, float &outLocalY);
void localToWorld(float localX, float localY, float &outWorldX, float &outWorldY);
float worldToLocalRotation(float worldRotation);
float localToWorldRotation(float localRotation);
/// Rotates the world transform the specified amount and sets isAppliedValid to false.
/// @param degrees Degrees.
void rotateWorld(float degrees);
float getWorldToLocalRotationX();
float getWorldToLocalRotationY();
BoneData &getData();
Skeleton &getSkeleton();
Bone *getParent();
Vector<Bone *> &getChildren();
/// The local X translation.
float getX();
void setX(float inValue);
/// The local Y translation.
float getY();
void setY(float inValue);
/// The local rotation.
float getRotation();
void setRotation(float inValue);
/// The local scaleX.
float getScaleX();
void setScaleX(float inValue);
/// The local scaleY.
float getScaleY();
void setScaleY(float inValue);
/// The local shearX.
float getShearX();
void setShearX(float inValue);
/// The local shearY.
float getShearY();
void setShearY(float inValue);
/// The rotation, as calculated by any constraints.
float getAppliedRotation();
void setAppliedRotation(float inValue);
/// The applied local x translation.
float getAX();
void setAX(float inValue);
/// The applied local y translation.
float getAY();
void setAY(float inValue);
/// The applied local scaleX.
float getAScaleX();
void setAScaleX(float inValue);
/// The applied local scaleY.
float getAScaleY();
void setAScaleY(float inValue);
/// The applied local shearX.
float getAShearX();
void setAShearX(float inValue);
/// The applied local shearY.
float getAShearY();
void setAShearY(float inValue);
float getA();
void setA(float inValue);
float getB();
void setB(float inValue);
float getC();
void setC(float inValue);
float getD();
void setD(float inValue);
float getWorldX();
void setWorldX(float inValue);
float getWorldY();
void setWorldY(float inValue);
float getWorldRotationX();
float getWorldRotationY();
/// Returns the magnitide (always positive) of the world scale X.
float getWorldScaleX();
/// Returns the magnitide (always positive) of the world scale Y.
float getWorldScaleY();
bool isAppliedValid();
void setAppliedValid(bool valid);
bool isActive();
void setActive(bool inValue);
private:
static bool yDown;
BoneData &_data;
Skeleton &_skeleton;
Bone *_parent;
Vector<Bone *> _children;
float _x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY;
float _ax, _ay, _arotation, _ascaleX, _ascaleY, _ashearX, _ashearY;
bool _appliedValid;
float _a, _b, _worldX;
float _c, _d, _worldY;
bool _sorted;
bool _active;
/// Computes the individual applied transform values from the world transform. This can be useful to perform processing using
/// the applied transform after the world transform has been modified directly (eg, by a constraint)..
///
/// Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation.
void updateAppliedTransform();
};
} // namespace spine
#endif /* Spine_Bone_h */

View File

@@ -0,0 +1,147 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/BoneData.h>
#include <assert.h>
using namespace spine;
BoneData::BoneData(int index, const String &name, BoneData *parent) : _index(index),
_name(name),
_parent(parent),
_length(0),
_x(0),
_y(0),
_rotation(0),
_scaleX(1),
_scaleY(1),
_shearX(0),
_shearY(0),
_transformMode(TransformMode_Normal),
_skinRequired(false) {
assert(index >= 0);
assert(_name.length() > 0);
}
int BoneData::getIndex() {
return _index;
}
const String &BoneData::getName() {
return _name;
}
BoneData *BoneData::getParent() {
return _parent;
}
float BoneData::getLength() {
return _length;
}
void BoneData::setLength(float inValue) {
_length = inValue;
}
float BoneData::getX() {
return _x;
}
void BoneData::setX(float inValue) {
_x = inValue;
}
float BoneData::getY() {
return _y;
}
void BoneData::setY(float inValue) {
_y = inValue;
}
float BoneData::getRotation() {
return _rotation;
}
void BoneData::setRotation(float inValue) {
_rotation = inValue;
}
float BoneData::getScaleX() {
return _scaleX;
}
void BoneData::setScaleX(float inValue) {
_scaleX = inValue;
}
float BoneData::getScaleY() {
return _scaleY;
}
void BoneData::setScaleY(float inValue) {
_scaleY = inValue;
}
float BoneData::getShearX() {
return _shearX;
}
void BoneData::setShearX(float inValue) {
_shearX = inValue;
}
float BoneData::getShearY() {
return _shearY;
}
void BoneData::setShearY(float inValue) {
_shearY = inValue;
}
TransformMode BoneData::getTransformMode() {
return _transformMode;
}
void BoneData::setTransformMode(TransformMode inValue) {
_transformMode = inValue;
}
bool BoneData::isSkinRequired() {
return _skinRequired;
}
void BoneData::setSkinRequired(bool inValue) {
_skinRequired = inValue;
}

View File

@@ -0,0 +1,123 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_BoneData_h
#define Spine_BoneData_h
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
#include <spine/TransformMode.h>
namespace spine {
class SP_API BoneData : public SpineObject {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class AnimationState;
friend class RotateTimeline;
friend class ScaleTimeline;
friend class ShearTimeline;
friend class TranslateTimeline;
public:
BoneData(int index, const String &name, BoneData *parent = NULL);
/// The index of the bone in Skeleton.Bones
int getIndex();
/// The name of the bone, which is unique within the skeleton.
const String &getName();
/// May be NULL.
BoneData *getParent();
float getLength();
void setLength(float inValue);
/// Local X translation.
float getX();
void setX(float inValue);
/// Local Y translation.
float getY();
void setY(float inValue);
/// Local rotation.
float getRotation();
void setRotation(float inValue);
/// Local scaleX.
float getScaleX();
void setScaleX(float inValue);
/// Local scaleY.
float getScaleY();
void setScaleY(float inValue);
/// Local shearX.
float getShearX();
void setShearX(float inValue);
/// Local shearY.
float getShearY();
void setShearY(float inValue);
/// The transform mode for how parent world transforms affect this bone.
TransformMode getTransformMode();
void setTransformMode(TransformMode inValue);
bool isSkinRequired();
void setSkinRequired(bool inValue);
private:
const int _index;
const String _name;
BoneData *_parent;
float _length;
float _x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY;
TransformMode _transformMode;
bool _skinRequired;
};
} // namespace spine
#endif /* Spine_BoneData_h */

View File

@@ -0,0 +1,47 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/BoundingBoxAttachment.h>
using namespace spine;
RTTI_IMPL(BoundingBoxAttachment, VertexAttachment)
BoundingBoxAttachment::BoundingBoxAttachment(const String& name) : VertexAttachment(name) {
}
Attachment* BoundingBoxAttachment::copy() {
BoundingBoxAttachment* copy = new (__FILE__, __LINE__) BoundingBoxAttachment(getName());
copyTo(copy);
return copy;
}

View File

@@ -0,0 +1,47 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_BoundingBoxAttachment_h
#define Spine_BoundingBoxAttachment_h
#include <spine/SpineObject.h>
#include <spine/VertexAttachment.h>
namespace spine {
/// Attachment that has a polygon for bounds checking.
class SP_API BoundingBoxAttachment : public VertexAttachment {
RTTI_DECL
explicit BoundingBoxAttachment(const String& name);
virtual Attachment* copy();
};
} // namespace spine
#endif /* Spine_BoundingBoxAttachment_h */

View File

@@ -0,0 +1,58 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/ClippingAttachment.h>
#include <spine/SlotData.h>
using namespace spine;
RTTI_IMPL(ClippingAttachment, VertexAttachment)
ClippingAttachment::ClippingAttachment(const String &name) : VertexAttachment(name), _endSlot(NULL) {
}
SlotData *ClippingAttachment::getEndSlot() {
return _endSlot;
}
void ClippingAttachment::setEndSlot(SlotData *inValue) {
_endSlot = inValue;
}
Attachment *ClippingAttachment::copy() {
ClippingAttachment *copy = new (__FILE__, __LINE__) ClippingAttachment(getName());
copyTo(copy);
copy->_endSlot = _endSlot;
return copy;
}

View File

@@ -0,0 +1,59 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_ClippingAttachment_h
#define Spine_ClippingAttachment_h
#include <spine/VertexAttachment.h>
namespace spine {
class SlotData;
class SP_API ClippingAttachment : public VertexAttachment {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class SkeletonClipping;
RTTI_DECL
public:
explicit ClippingAttachment(const String& name);
SlotData* getEndSlot();
void setEndSlot(SlotData* inValue);
virtual Attachment* copy();
private:
SlotData* _endSlot;
};
} // namespace spine
#endif /* Spine_ClippingAttachment_h */

View File

@@ -0,0 +1,93 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef SPINE_COLOR_H
#define SPINE_COLOR_H
#include <spine/MathUtil.h>
namespace spine {
class SP_API Color : public SpineObject {
public:
Color() : r(0), g(0), b(0), a(0) {
}
Color(float r, float g, float b, float a) : r(r), g(g), b(b), a(a) {
clamp();
}
inline Color &set(float _r, float _g, float _b, float _a) {
this->r = _r;
this->g = _g;
this->b = _b;
this->a = _a;
clamp();
return *this;
}
inline Color &set(const Color &other) {
r = other.r;
g = other.g;
b = other.b;
a = other.a;
clamp();
return *this;
}
inline Color &add(float _r, float _g, float _b, float _a) {
this->r += _r;
this->g += _g;
this->b += _b;
this->a += _a;
clamp();
return *this;
}
inline Color &add(const Color &other) {
r += other.r;
g += other.g;
b += other.b;
a += other.a;
clamp();
return *this;
}
inline Color &clamp() {
r = MathUtil::clamp(this->r, 0, 1);
g = MathUtil::clamp(this->g, 0, 1);
b = MathUtil::clamp(this->b, 0, 1);
a = MathUtil::clamp(this->a, 0, 1);
return *this;
}
float r, g, b, a;
};
} // namespace spine
#endif //SPINE_COLOR_H

View File

@@ -0,0 +1,144 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/ColorTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/Bone.h>
#include <spine/Slot.h>
#include <spine/SlotData.h>
#include <spine/TimelineType.h>
using namespace spine;
RTTI_IMPL(ColorTimeline, CurveTimeline)
const int ColorTimeline::ENTRIES = 5;
const int ColorTimeline::PREV_TIME = -5;
const int ColorTimeline::PREV_R = -4;
const int ColorTimeline::PREV_G = -3;
const int ColorTimeline::PREV_B = -2;
const int ColorTimeline::PREV_A = -1;
const int ColorTimeline::R = 1;
const int ColorTimeline::G = 2;
const int ColorTimeline::B = 3;
const int ColorTimeline::A = 4;
ColorTimeline::ColorTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0) {
_frames.setSize(frameCount * ENTRIES, 0);
}
void ColorTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
SP_UNUSED(direction);
Slot *slotP = skeleton._slots[_slotIndex];
Slot &slot = *slotP;
if (!slot._bone.isActive()) return;
if (time < _frames[0]) {
switch (blend) {
case MixBlend_Setup:
slot._color.set(slot._data._color);
return;
case MixBlend_First: {
Color &color = slot._color, setup = slot._data._color;
color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha,
(setup.a - color.a) * alpha);
}
default:;
}
return;
}
float r, g, b, a;
if (time >= _frames[_frames.size() - ENTRIES]) {
// Time is after last frame.
size_t i = _frames.size();
r = _frames[i + PREV_R];
g = _frames[i + PREV_G];
b = _frames[i + PREV_B];
a = _frames[i + PREV_A];
} else {
// Interpolate between the previous frame and the current frame.
size_t frame = (size_t)Animation::binarySearch(_frames, time, ENTRIES);
r = _frames[frame + PREV_R];
g = _frames[frame + PREV_G];
b = _frames[frame + PREV_B];
a = _frames[frame + PREV_A];
float frameTime = _frames[frame];
float percent = getCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime));
r += (_frames[frame + R] - r) * percent;
g += (_frames[frame + G] - g) * percent;
b += (_frames[frame + B] - b) * percent;
a += (_frames[frame + A] - a) * percent;
}
if (alpha == 1) {
slot.getColor().set(r, g, b, a);
} else {
Color &color = slot.getColor();
if (blend == MixBlend_Setup) color.set(slot.getData().getColor());
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
}
}
int ColorTimeline::getPropertyId() {
return ((int)TimelineType_Color << 24) + _slotIndex;
}
void ColorTimeline::setFrame(int frameIndex, float time, float r, float g, float b, float a) {
frameIndex *= ENTRIES;
_frames[frameIndex] = time;
_frames[frameIndex + R] = r;
_frames[frameIndex + G] = g;
_frames[frameIndex + B] = b;
_frames[frameIndex + A] = a;
}
int ColorTimeline::getSlotIndex() {
return _slotIndex;
}
void ColorTimeline::setSlotIndex(int inValue) {
_slotIndex = inValue;
}
Vector<float> &ColorTimeline::getFrames() {
return _frames;
}

View File

@@ -0,0 +1,80 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_ColorTimeline_h
#define Spine_ColorTimeline_h
#include <spine/CurveTimeline.h>
namespace spine {
class SP_API ColorTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
static const int ENTRIES;
explicit ColorTimeline(int frameCount);
virtual void
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
MixDirection direction);
virtual int getPropertyId();
/// Sets the time and value of the specified keyframe.
void setFrame(int frameIndex, float time, float r, float g, float b, float a);
int getSlotIndex();
void setSlotIndex(int inValue);
Vector<float> &getFrames();
protected:
static const int PREV_TIME;
static const int PREV_R;
static const int PREV_G;
static const int PREV_B;
static const int PREV_A;
static const int R;
static const int G;
static const int B;
static const int A;
private:
int _slotIndex;
Vector<float> _frames;
};
} // namespace spine
#endif /* Spine_ColorTimeline_h */

View File

@@ -0,0 +1,45 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/Constraint.h>
using namespace spine;
RTTI_IMPL(Constraint, Updatable)
Constraint::Constraint() {
}
Constraint::~Constraint() {
}

View File

@@ -0,0 +1,53 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_Constraint_h
#define Spine_Constraint_h
#include <spine/Updatable.h>
namespace spine {
/// The interface for all constraints.
class SP_API Constraint : public Updatable {
RTTI_DECL
public:
Constraint();
virtual ~Constraint();
virtual void update() = 0;
/// The ordinal for the order a skeleton's constraints will be applied.
virtual int getOrder() = 0;
};
} // namespace spine
#endif /* Spine_Constraint_h */

View File

@@ -0,0 +1,62 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/ConstraintData.h>
using namespace spine;
ConstraintData::ConstraintData(const String& name) : _name(name), _order(0), _skinRequired(false) {
}
ConstraintData::~ConstraintData() {
}
const String& ConstraintData::getName() {
return _name;
}
size_t ConstraintData::getOrder() {
return _order;
}
void ConstraintData::setOrder(size_t inValue) {
_order = inValue;
}
bool ConstraintData::isSkinRequired() {
return _skinRequired;
}
void ConstraintData::setSkinRequired(bool inValue) {
_skinRequired = inValue;
}

View File

@@ -0,0 +1,62 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_Constraint_h
#define Spine_Constraint_h
#include <spine/SpineString.h>
#include <spine/Updatable.h>
namespace spine {
/// The interface for all constraints.
class SP_API ConstraintData : public SpineObject {
public:
ConstraintData(const String& name);
virtual ~ConstraintData();
/// The IK constraint's name, which is unique within the skeleton.
const String& getName();
/// The ordinal for the order a skeleton's constraints will be applied.
size_t getOrder();
void setOrder(size_t inValue);
/// Whether the constraint is only active for a specific skin.
bool isSkinRequired();
void setSkinRequired(bool inValue);
private:
const String _name;
size_t _order;
bool _skinRequired;
};
} // namespace spine
#endif /* Spine_Constraint_h */

View File

@@ -0,0 +1,127 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_ContainerUtil_h
#define Spine_ContainerUtil_h
#include <spine/Extension.h>
#include <spine/HashMap.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
#include <spine/Vector.h>
#include <assert.h>
namespace spine {
class SP_API ContainerUtil : public SpineObject {
public:
/// Finds an item by comparing each item's name.
/// It is more efficient to cache the results of this method than to call it multiple times.
/// @return May be NULL.
template <typename T>
static T* findWithName(Vector<T*>& items, const String& name) {
assert(name.length() > 0);
for (size_t i = 0; i < items.size(); ++i) {
T* item = items[i];
if (item->getName() == name) {
return item;
}
}
return NULL;
}
/// @return -1 if the item was not found.
template <typename T>
static int findIndexWithName(Vector<T*>& items, const String& name) {
assert(name.length() > 0);
for (size_t i = 0, len = items.size(); i < len; ++i) {
T* item = items[i];
if (item->getName() == name) {
return static_cast<int>(i);
}
}
return -1;
}
/// Finds an item by comparing each item's name.
/// It is more efficient to cache the results of this method than to call it multiple times.
/// @return May be NULL.
template <typename T>
static T* findWithDataName(Vector<T*>& items, const String& name) {
assert(name.length() > 0);
for (size_t i = 0; i < items.size(); ++i) {
T* item = items[i];
if (item->getData().getName() == name) {
return item;
}
}
return NULL;
}
/// @return -1 if the item was not found.
template <typename T>
static int findIndexWithDataName(Vector<T*>& items, const String& name) {
assert(name.length() > 0);
for (size_t i = 0, len = items.size(); i < len; ++i) {
T* item = items[i];
if (item->getData().getName() == name) {
return static_cast<int>(i);
}
}
return -1;
}
template <typename T>
static void cleanUpVectorOfPointers(Vector<T*>& items) {
for (int i = (int)items.size() - 1; i >= 0; i--) {
T* item = items[i];
delete item;
items.removeAt(i);
}
}
private:
// ctor, copy ctor, and assignment should be private in a Singleton
ContainerUtil();
ContainerUtil(const ContainerUtil&);
ContainerUtil& operator=(const ContainerUtil&);
};
} // namespace spine
#endif /* Spine_ContainerUtil_h */

View File

@@ -0,0 +1,127 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/CurveTimeline.h>
#include <spine/MathUtil.h>
using namespace spine;
RTTI_IMPL(CurveTimeline, Timeline)
const float CurveTimeline::LINEAR = 0;
const float CurveTimeline::STEPPED = 1;
const float CurveTimeline::BEZIER = 2;
const int CurveTimeline::BEZIER_SIZE = 10 * 2 - 1;
CurveTimeline::CurveTimeline(int frameCount) {
assert(frameCount > 0);
_curves.setSize((frameCount - 1) * BEZIER_SIZE, 0);
}
CurveTimeline::~CurveTimeline() {
}
size_t CurveTimeline::getFrameCount() {
return _curves.size() / BEZIER_SIZE + 1;
}
void CurveTimeline::setLinear(size_t frameIndex) {
_curves[frameIndex * BEZIER_SIZE] = LINEAR;
}
void CurveTimeline::setStepped(size_t frameIndex) {
_curves[frameIndex * BEZIER_SIZE] = STEPPED;
}
void CurveTimeline::setCurve(size_t frameIndex, float cx1, float cy1, float cx2, float cy2) {
float tmpx = (-cx1 * 2 + cx2) * 0.03f, tmpy = (-cy1 * 2 + cy2) * 0.03f;
float dddfx = ((cx1 - cx2) * 3 + 1) * 0.006f, dddfy = ((cy1 - cy2) * 3 + 1) * 0.006f;
float ddfx = tmpx * 2 + dddfx, ddfy = tmpy * 2 + dddfy;
float dfx = cx1 * 0.3f + tmpx + dddfx * 0.16666667f, dfy = cy1 * 0.3f + tmpy + dddfy * 0.16666667f;
size_t i = frameIndex * BEZIER_SIZE;
_curves[i++] = BEZIER;
float x = dfx, y = dfy;
for (size_t n = i + BEZIER_SIZE - 1; i < n; i += 2) {
_curves[i] = x;
_curves[i + 1] = y;
dfx += ddfx;
dfy += ddfy;
ddfx += dddfx;
ddfy += dddfy;
x += dfx;
y += dfy;
}
}
float CurveTimeline::getCurvePercent(size_t frameIndex, float percent) {
percent = MathUtil::clamp(percent, 0, 1);
size_t i = frameIndex * BEZIER_SIZE;
float type = _curves[i];
if (type == LINEAR) {
return percent;
}
if (type == STEPPED) {
return 0;
}
i++;
float x = 0;
for (size_t start = i, n = i + BEZIER_SIZE - 1; i < n; i += 2) {
x = _curves[i];
if (x >= percent) {
float prevX, prevY;
if (i == start) {
prevX = 0;
prevY = 0;
} else {
prevX = _curves[i - 2];
prevY = _curves[i - 1];
}
return prevY + (_curves[i + 1] - prevY) * (percent - prevX) / (x - prevX);
}
}
float y = _curves[i - 1];
return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1.
}
float CurveTimeline::getCurveType(size_t frameIndex) {
return _curves[frameIndex * BEZIER_SIZE];
}

View File

@@ -0,0 +1,76 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_CurveTimeline_h
#define Spine_CurveTimeline_h
#include <spine/Timeline.h>
#include <spine/Vector.h>
namespace spine {
/// Base class for frames that use an interpolation bezier curve.
class SP_API CurveTimeline : public Timeline {
RTTI_DECL
public:
explicit CurveTimeline(int frameCount);
virtual ~CurveTimeline();
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixBlend blend, MixDirection direction) = 0;
virtual int getPropertyId() = 0;
size_t getFrameCount();
void setLinear(size_t frameIndex);
void setStepped(size_t frameIndex);
/// Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next.
/// cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of
/// the difference between the keyframe's values.
void setCurve(size_t frameIndex, float cx1, float cy1, float cx2, float cy2);
float getCurvePercent(size_t frameIndex, float percent);
float getCurveType(size_t frameIndex);
protected:
static const float LINEAR;
static const float STEPPED;
static const float BEZIER;
static const int BEZIER_SIZE;
private:
Vector<float> _curves; // type, x, y, ...
};
} // namespace spine
#endif /* Spine_CurveTimeline_h */

View File

@@ -0,0 +1,126 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef SPINE_DEBUG_H
#define SPINE_DEBUG_H
#include <spine/Extension.h>
#include <map>
namespace spine {
class SP_API DebugExtension : public SpineExtension {
struct Allocation {
void *address;
size_t size;
const char *fileName;
int line;
Allocation() : address(NULL), size(0), fileName(NULL), line(0) {
}
Allocation(void *a, size_t s, const char *f, int l) : address(a), size(s), fileName(f), line(l) {
}
};
public:
DebugExtension(SpineExtension *extension) : _extension(extension), _allocations(0), _reallocations(0), _frees(0) {
}
void reportLeaks() {
for (std::map<void *, Allocation>::iterator it = _allocated.begin(); it != _allocated.end(); it++) {
printf("\"%s:%i (%zu bytes at %p)\n", it->second.fileName, it->second.line, it->second.size, it->second.address);
}
printf("allocations: %zu, reallocations: %zu, frees: %zu\n", _allocations, _reallocations, _frees);
if (_allocated.empty()) printf("No leaks detected");
}
void clearAllocations() {
_allocated.clear();
_usedMemory = 0;
}
virtual void *_alloc(size_t size, const char *file, int line) {
void *result = _extension->_alloc(size, file, line);
_allocated[result] = Allocation(result, size, file, line);
_allocations++;
_usedMemory += size;
return result;
}
virtual void *_calloc(size_t size, const char *file, int line) {
void *result = _extension->_calloc(size, file, line);
_allocated[result] = Allocation(result, size, file, line);
_allocations++;
_usedMemory += size;
return result;
}
virtual void *_realloc(void *ptr, size_t size, const char *file, int line) {
if (_allocated.count(ptr)) _usedMemory -= _allocated[ptr].size;
_allocated.erase(ptr);
void *result = _extension->_realloc(ptr, size, file, line);
_reallocations++;
_allocated[result] = Allocation(result, size, file, line);
_usedMemory += size;
return result;
}
virtual void _free(void *mem, const char *file, int line) {
if (_allocated.count(mem)) {
_extension->_free(mem, file, line);
_frees++;
_usedMemory -= _allocated[mem].size;
_allocated.erase(mem);
return;
}
printf("%s:%i (address %p): Double free or not allocated through SpineExtension\n", file, line, mem);
_extension->_free(mem, file, line);
}
virtual char *_readFile(const String &path, int *length) {
return _extension->_readFile(path, length);
}
size_t getUsedMemory() {
return _usedMemory;
}
private:
SpineExtension *_extension;
std::map<void *, Allocation> _allocated;
size_t _allocations;
size_t _reallocations;
size_t _frees;
size_t _usedMemory;
};
} // namespace spine
#endif //SPINE_DEBUG_H

View File

@@ -0,0 +1,297 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/DeformTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/VertexAttachment.h>
#include <spine/Animation.h>
#include <spine/Bone.h>
#include <spine/Slot.h>
#include <spine/SlotData.h>
#include <spine/TimelineType.h>
using namespace spine;
RTTI_IMPL(DeformTimeline, CurveTimeline)
DeformTimeline::DeformTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0), _attachment(NULL) {
_frames.ensureCapacity(frameCount);
_frameVertices.ensureCapacity(frameCount);
_frames.setSize(frameCount, 0);
for (int i = 0; i < frameCount; ++i) {
Vector<float> vec;
_frameVertices.add(vec);
}
}
void DeformTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
SP_UNUSED(direction);
Slot *slotP = skeleton._slots[_slotIndex];
Slot &slot = *slotP;
if (!slot._bone.isActive()) return;
Attachment *slotAttachment = slot.getAttachment();
if (slotAttachment == NULL || !slotAttachment->getRTTI().instanceOf(VertexAttachment::rtti)) {
return;
}
VertexAttachment *attachment = static_cast<VertexAttachment *>(slotAttachment);
if (attachment->_deformAttachment != _attachment) {
return;
}
Vector<float> &deformArray = slot._deform;
if (deformArray.size() == 0) {
blend = MixBlend_Setup;
}
Vector<Vector<float> > &frameVertices = _frameVertices;
size_t vertexCount = frameVertices[0].size();
Vector<float> &frames = _frames;
if (time < _frames[0]) {
switch (blend) {
case MixBlend_Setup:
deformArray.clear();
return;
case MixBlend_First: {
if (alpha == 1) {
deformArray.clear();
return;
}
deformArray.setSize(vertexCount, 0);
Vector<float> &deformInner = deformArray;
if (attachment->getBones().size() == 0) {
// Unweighted vertex positions.
Vector<float> &setupVertices = attachment->getVertices();
for (size_t i = 0; i < vertexCount; i++)
deformInner[i] += (setupVertices[i] - deformInner[i]) * alpha;
} else {
// Weighted deform offsets.
alpha = 1 - alpha;
for (size_t i = 0; i < vertexCount; i++)
deformInner[i] *= alpha;
}
}
case MixBlend_Replace:
case MixBlend_Add:
return;
}
}
deformArray.setSize(vertexCount, 0);
Vector<float> &deform = deformArray;
if (time >= frames[frames.size() - 1]) { // Time is after last frame.
Vector<float> &lastVertices = frameVertices[frames.size() - 1];
if (alpha == 1) {
if (blend == MixBlend_Add) {
VertexAttachment *vertexAttachment = static_cast<VertexAttachment *>(slotAttachment);
if (vertexAttachment->getBones().size() == 0) {
// Unweighted vertex positions, no alpha.
Vector<float> &setupVertices = vertexAttachment->getVertices();
for (size_t i = 0; i < vertexCount; i++)
deform[i] += lastVertices[i] - setupVertices[i];
} else {
// Weighted deform offsets, no alpha.
for (size_t i = 0; i < vertexCount; i++)
deform[i] += lastVertices[i];
}
} else {
// Vertex positions or deform offsets, no alpha.
memcpy(deform.buffer(), lastVertices.buffer(), vertexCount * sizeof(float));
}
} else {
switch (blend) {
case MixBlend_Setup: {
VertexAttachment *vertexAttachment = static_cast<VertexAttachment *>(slotAttachment);
if (vertexAttachment->getBones().size() == 0) {
// Unweighted vertex positions, with alpha.
Vector<float> &setupVertices = vertexAttachment->getVertices();
for (size_t i = 0; i < vertexCount; i++) {
float setup = setupVertices[i];
deform[i] = setup + (lastVertices[i] - setup) * alpha;
}
} else {
// Weighted deform offsets, with alpha.
for (size_t i = 0; i < vertexCount; i++)
deform[i] = lastVertices[i] * alpha;
}
break;
}
case MixBlend_First:
case MixBlend_Replace:
// Vertex positions or deform offsets, with alpha.
for (size_t i = 0; i < vertexCount; i++)
deform[i] += (lastVertices[i] - deform[i]) * alpha;
break;
case MixBlend_Add:
VertexAttachment *vertexAttachment = static_cast<VertexAttachment *>(slotAttachment);
if (vertexAttachment->getBones().size() == 0) {
// Unweighted vertex positions, no alpha.
Vector<float> &setupVertices = vertexAttachment->getVertices();
for (size_t i = 0; i < vertexCount; i++)
deform[i] += (lastVertices[i] - setupVertices[i]) * alpha;
} else {
// Weighted deform offsets, alpha.
for (size_t i = 0; i < vertexCount; i++)
deform[i] += lastVertices[i] * alpha;
}
}
}
return;
}
// Interpolate between the previous frame and the current frame.
int frame = Animation::binarySearch(frames, time);
Vector<float> &prevVertices = frameVertices[frame - 1];
Vector<float> &nextVertices = frameVertices[frame];
float frameTime = frames[frame];
float percent = getCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));
if (alpha == 1) {
if (blend == MixBlend_Add) {
VertexAttachment *vertexAttachment = static_cast<VertexAttachment *>(slotAttachment);
if (vertexAttachment->getBones().size() == 0) {
// Unweighted vertex positions, no alpha.
Vector<float> &setupVertices = vertexAttachment->getVertices();
for (size_t i = 0; i < vertexCount; i++) {
float prev = prevVertices[i];
deform[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i];
}
} else {
// Weighted deform offsets, no alpha.
for (size_t i = 0; i < vertexCount; i++) {
float prev = prevVertices[i];
deform[i] += prev + (nextVertices[i] - prev) * percent;
}
}
} else {
// Vertex positions or deform offsets, no alpha.
for (size_t i = 0; i < vertexCount; i++) {
float prev = prevVertices[i];
deform[i] = prev + (nextVertices[i] - prev) * percent;
}
}
} else {
switch (blend) {
case MixBlend_Setup: {
VertexAttachment *vertexAttachment = static_cast<VertexAttachment *>(slotAttachment);
if (vertexAttachment->getBones().size() == 0) {
// Unweighted vertex positions, with alpha.
Vector<float> &setupVertices = vertexAttachment->getVertices();
for (size_t i = 0; i < vertexCount; i++) {
float prev = prevVertices[i], setup = setupVertices[i];
deform[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
}
} else {
// Weighted deform offsets, with alpha.
for (size_t i = 0; i < vertexCount; i++) {
float prev = prevVertices[i];
deform[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
}
}
break;
}
case MixBlend_First:
case MixBlend_Replace:
// Vertex positions or deform offsets, with alpha.
for (size_t i = 0; i < vertexCount; i++) {
float prev = prevVertices[i];
deform[i] += (prev + (nextVertices[i] - prev) * percent - deform[i]) * alpha;
}
break;
case MixBlend_Add:
VertexAttachment *vertexAttachment = static_cast<VertexAttachment *>(slotAttachment);
if (vertexAttachment->getBones().size() == 0) {
// Unweighted vertex positions, with alpha.
Vector<float> &setupVertices = vertexAttachment->getVertices();
for (size_t i = 0; i < vertexCount; i++) {
float prev = prevVertices[i];
deform[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha;
}
} else {
// Weighted deform offsets, with alpha.
for (size_t i = 0; i < vertexCount; i++) {
float prev = prevVertices[i];
deform[i] += (prev + (nextVertices[i] - prev) * percent) * alpha;
}
}
}
}
}
int DeformTimeline::getPropertyId() {
assert(_attachment != NULL);
return ((int)TimelineType_Deform << 24) + _attachment->_id + _slotIndex;
}
void DeformTimeline::setFrame(int frameIndex, float time, Vector<float> &vertices) {
_frames[frameIndex] = time;
_frameVertices[frameIndex].clear();
_frameVertices[frameIndex].addAll(vertices);
}
int DeformTimeline::getSlotIndex() {
return _slotIndex;
}
void DeformTimeline::setSlotIndex(int inValue) {
_slotIndex = inValue;
}
Vector<float> &DeformTimeline::getFrames() {
return _frames;
}
Vector<Vector<float> > &DeformTimeline::getVertices() {
return _frameVertices;
}
VertexAttachment *DeformTimeline::getAttachment() {
return _attachment;
}
void DeformTimeline::setAttachment(VertexAttachment *inValue) {
_attachment = inValue;
}

View File

@@ -0,0 +1,69 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_DeformTimeline_h
#define Spine_DeformTimeline_h
#include <spine/CurveTimeline.h>
namespace spine {
class VertexAttachment;
class SP_API DeformTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
explicit DeformTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixBlend blend, MixDirection direction);
virtual int getPropertyId();
/// Sets the time and value of the specified keyframe.
void setFrame(int frameIndex, float time, Vector<float>& vertices);
int getSlotIndex();
void setSlotIndex(int inValue);
Vector<float>& getFrames();
Vector<Vector<float> >& getVertices();
VertexAttachment* getAttachment();
void setAttachment(VertexAttachment* inValue);
private:
int _slotIndex;
Vector<float> _frames;
Vector<Vector<float> > _frameVertices;
VertexAttachment* _attachment;
};
} // namespace spine
#endif /* Spine_DeformTimeline_h */

View File

@@ -0,0 +1,124 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/DrawOrderTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/Slot.h>
#include <spine/SlotData.h>
#include <spine/TimelineType.h>
using namespace spine;
RTTI_IMPL(DrawOrderTimeline, Timeline)
DrawOrderTimeline::DrawOrderTimeline(int frameCount) : Timeline() {
_frames.ensureCapacity(frameCount);
_drawOrders.ensureCapacity(frameCount);
_frames.setSize(frameCount, 0);
for (int i = 0; i < frameCount; ++i) {
Vector<int> vec;
_drawOrders.add(vec);
}
}
void DrawOrderTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
SP_UNUSED(alpha);
Vector<Slot *> &drawOrder = skeleton._drawOrder;
Vector<Slot *> &slots = skeleton._slots;
if (direction == MixDirection_Out && blend == MixBlend_Setup) {
drawOrder.clear();
drawOrder.ensureCapacity(slots.size());
for (size_t i = 0, n = slots.size(); i < n; ++i)
drawOrder.add(slots[i]);
return;
}
if (time < _frames[0]) {
if (blend == MixBlend_Setup || blend == MixBlend_First) {
drawOrder.clear();
drawOrder.ensureCapacity(slots.size());
for (size_t i = 0, n = slots.size(); i < n; ++i)
drawOrder.add(slots[i]);
}
return;
}
size_t frame;
if (time >= _frames[_frames.size() - 1]) {
// Time is after last frame.
frame = _frames.size() - 1;
} else
frame = (size_t)Animation::binarySearch(_frames, time) - 1;
Vector<int> &drawOrderToSetupIndex = _drawOrders[frame];
if (drawOrderToSetupIndex.size() == 0) {
drawOrder.clear();
for (size_t i = 0, n = slots.size(); i < n; ++i)
drawOrder.add(slots[i]);
} else {
for (size_t i = 0, n = drawOrderToSetupIndex.size(); i < n; ++i)
drawOrder[i] = slots[drawOrderToSetupIndex[i]];
}
}
int DrawOrderTimeline::getPropertyId() {
return ((int)TimelineType_DrawOrder << 24);
}
void DrawOrderTimeline::setFrame(size_t frameIndex, float time, Vector<int> &drawOrder) {
_frames[frameIndex] = time;
_drawOrders[frameIndex].clear();
_drawOrders[frameIndex].addAll(drawOrder);
}
Vector<float> &DrawOrderTimeline::getFrames() {
return _frames;
}
Vector<Vector<int> > &DrawOrderTimeline::getDrawOrders() {
return _drawOrders;
}
size_t DrawOrderTimeline::getFrameCount() {
return _frames.size();
}

View File

@@ -0,0 +1,63 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_DrawOrderTimeline_h
#define Spine_DrawOrderTimeline_h
#include <spine/Timeline.h>
namespace spine {
class SP_API DrawOrderTimeline : public Timeline {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
explicit DrawOrderTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixBlend blend, MixDirection direction);
virtual int getPropertyId();
/// Sets the time and value of the specified keyframe.
/// @param drawOrder May be NULL to use bind pose draw order
void setFrame(size_t frameIndex, float time, Vector<int>& drawOrder);
Vector<float>& getFrames();
Vector<Vector<int> >& getDrawOrders();
size_t getFrameCount();
private:
Vector<float> _frames;
Vector<Vector<int> > _drawOrders;
};
} // namespace spine
#endif /* Spine_DrawOrderTimeline_h */

View File

@@ -0,0 +1,93 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/Event.h>
#include <spine/EventData.h>
spine::Event::Event(float time, const spine::EventData &data) : _data(data),
_time(time),
_intValue(0),
_floatValue(0),
_stringValue(),
_volume(1),
_balance(0) {
}
const spine::EventData &spine::Event::getData() {
return _data;
}
float spine::Event::getTime() {
return _time;
}
int spine::Event::getIntValue() {
return _intValue;
}
void spine::Event::setIntValue(int inValue) {
_intValue = inValue;
}
float spine::Event::getFloatValue() {
return _floatValue;
}
void spine::Event::setFloatValue(float inValue) {
_floatValue = inValue;
}
const spine::String &spine::Event::getStringValue() {
return _stringValue;
}
void spine::Event::setStringValue(const spine::String &inValue) {
_stringValue = inValue;
}
float spine::Event::getVolume() {
return _volume;
}
void spine::Event::setVolume(float inValue) {
_volume = inValue;
}
float spine::Event::getBalance() {
return _balance;
}
void spine::Event::setBalance(float inValue) {
_balance = inValue;
}

View File

@@ -0,0 +1,86 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_Event_h
#define Spine_Event_h
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
namespace spine {
class EventData;
/// Stores the current pose values for an Event.
class SP_API Event : public SpineObject {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class AnimationState;
public:
Event(float time, const EventData &data);
const EventData &getData();
/// The animation time this event was keyed.
float getTime();
int getIntValue();
void setIntValue(int inValue);
float getFloatValue();
void setFloatValue(float inValue);
const String &getStringValue();
void setStringValue(const String &inValue);
float getVolume();
void setVolume(float inValue);
float getBalance();
void setBalance(float inValue);
private:
const EventData &_data;
const float _time;
int _intValue;
float _floatValue;
String _stringValue;
float _volume;
float _balance;
};
} // namespace spine
#endif /* Spine_Event_h */

View File

@@ -0,0 +1,99 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/EventData.h>
#include <assert.h>
spine::EventData::EventData(const spine::String &name) : _name(name),
_intValue(0),
_floatValue(0),
_stringValue(),
_audioPath(),
_volume(1),
_balance(0) {
assert(_name.length() > 0);
}
/// The name of the event, which is unique within the skeleton.
const spine::String &spine::EventData::getName() const {
return _name;
}
int spine::EventData::getIntValue() {
return _intValue;
}
void spine::EventData::setIntValue(int inValue) {
_intValue = inValue;
}
float spine::EventData::getFloatValue() {
return _floatValue;
}
void spine::EventData::setFloatValue(float inValue) {
_floatValue = inValue;
}
const spine::String &spine::EventData::getStringValue() {
return _stringValue;
}
void spine::EventData::setStringValue(const spine::String &inValue) {
this->_stringValue = inValue;
}
const spine::String &spine::EventData::getAudioPath() {
return _audioPath;
}
void spine::EventData::setAudioPath(const spine::String &inValue) {
_audioPath = inValue;
}
float spine::EventData::getVolume() {
return _volume;
}
void spine::EventData::setVolume(float inValue) {
_volume = inValue;
}
float spine::EventData::getBalance() {
return _balance;
}
void spine::EventData::setBalance(float inValue) {
_balance = inValue;
}

View File

@@ -0,0 +1,86 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_EventData_h
#define Spine_EventData_h
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
namespace spine {
/// Stores the setup pose values for an Event.
class SP_API EventData : public SpineObject {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class Event;
public:
explicit EventData(const String &name);
/// The name of the event, which is unique within the skeleton.
const String &getName() const;
int getIntValue();
void setIntValue(int inValue);
float getFloatValue();
void setFloatValue(float inValue);
const String &getStringValue();
void setStringValue(const String &inValue);
const String &getAudioPath();
void setAudioPath(const String &inValue);
float getVolume();
void setVolume(float inValue);
float getBalance();
void setBalance(float inValue);
private:
const String _name;
int _intValue;
float _floatValue;
String _stringValue;
String _audioPath;
float _volume;
float _balance;
};
} // namespace spine
#endif /* Spine_EventData_h */

View File

@@ -0,0 +1,110 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/EventTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/ContainerUtil.h>
#include <spine/EventData.h>
#include <spine/Slot.h>
#include <spine/SlotData.h>
#include <spine/TimelineType.h>
#include <float.h>
using namespace spine;
RTTI_IMPL(EventTimeline, Timeline)
EventTimeline::EventTimeline(int frameCount) : Timeline() {
_frames.setSize(frameCount, 0);
_events.setSize(frameCount, NULL);
}
EventTimeline::~EventTimeline() {
ContainerUtil::cleanUpVectorOfPointers(_events);
}
void EventTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction) {
if (pEvents == NULL) return;
Vector<Event *> &events = *pEvents;
size_t frameCount = _frames.size();
if (lastTime > time) {
// Fire events after last time for looped animations.
apply(skeleton, lastTime, FLT_MAX, pEvents, alpha, blend, direction);
lastTime = -1.0f;
} else if (lastTime >= _frames[frameCount - 1]) {
// Last time is after last frame.
return;
}
if (time < _frames[0]) return; // Time is before first frame.
int frame;
if (lastTime < _frames[0]) {
frame = 0;
} else {
frame = Animation::binarySearch(_frames, lastTime);
float frameTime = _frames[frame];
while (frame > 0) {
// Fire multiple events with the same frame.
if (_frames[frame - 1] != frameTime) break;
frame--;
}
}
for (; (size_t)frame < frameCount && time >= _frames[frame]; ++frame)
events.add(_events[frame]);
}
int EventTimeline::getPropertyId() {
return ((int)TimelineType_Event << 24);
}
void EventTimeline::setFrame(size_t frameIndex, Event *event) {
_frames[frameIndex] = event->getTime();
_events[frameIndex] = event;
}
Vector<float> &EventTimeline::getFrames() { return _frames; }
Vector<Event *> &EventTimeline::getEvents() { return _events; }
size_t EventTimeline::getFrameCount() { return _frames.size(); }

View File

@@ -0,0 +1,64 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_EventTimeline_h
#define Spine_EventTimeline_h
#include <spine/Timeline.h>
namespace spine {
class SP_API EventTimeline : public Timeline {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
explicit EventTimeline(int frameCount);
~EventTimeline();
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixBlend blend, MixDirection direction);
virtual int getPropertyId();
/// Sets the time and value of the specified keyframe.
void setFrame(size_t frameIndex, Event* event);
Vector<float>& getFrames();
Vector<Event*>& getEvents();
size_t getFrameCount();
private:
Vector<float> _frames;
Vector<Event*> _events;
};
} // namespace spine
#endif /* Spine_EventTimeline_h */

View File

@@ -0,0 +1,127 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/Extension.h>
#include <spine/SpineString.h>
#include <assert.h>
using namespace spine;
SpineExtension *SpineExtension::_instance = NULL;
void SpineExtension::setInstance(SpineExtension *inValue) {
assert(inValue);
_instance = inValue;
}
SpineExtension *SpineExtension::getInstance() {
if (!_instance) _instance = spine::getDefaultExtension();
assert(_instance);
return _instance;
}
SpineExtension::~SpineExtension() {
}
SpineExtension::SpineExtension() {
}
DefaultSpineExtension::~DefaultSpineExtension() {
}
void *DefaultSpineExtension::_alloc(size_t size, const char *file, int line) {
SP_UNUSED(file);
SP_UNUSED(line);
if (size == 0)
return 0;
void *ptr = ::malloc(size);
return ptr;
}
void *DefaultSpineExtension::_calloc(size_t size, const char *file, int line) {
SP_UNUSED(file);
SP_UNUSED(line);
if (size == 0)
return 0;
void *ptr = ::malloc(size);
if (ptr) {
memset(ptr, 0, size);
}
return ptr;
}
void *DefaultSpineExtension::_realloc(void *ptr, size_t size, const char *file, int line) {
SP_UNUSED(file);
SP_UNUSED(line);
void *mem = NULL;
if (size == 0)
return 0;
if (ptr == NULL)
mem = ::malloc(size);
else
mem = ::realloc(ptr, size);
return mem;
}
void DefaultSpineExtension::_free(void *mem, const char *file, int line) {
SP_UNUSED(file);
SP_UNUSED(line);
::free(mem);
}
char *DefaultSpineExtension::_readFile(const String &path, int *length) {
char *data;
FILE *file = fopen(path.buffer(), "rb");
if (!file) return 0;
fseek(file, 0, SEEK_END);
*length = (int)ftell(file);
fseek(file, 0, SEEK_SET);
data = SpineExtension::alloc<char>(*length, __FILE__, __LINE__);
fread(data, 1, *length, file);
fclose(file);
return data;
}
DefaultSpineExtension::DefaultSpineExtension() : SpineExtension() {
}

View File

@@ -0,0 +1,117 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_Extension_h
#define Spine_Extension_h
#include <spine/dll.h>
#include <stdlib.h>
#define SP_UNUSED(x) (void)(x)
namespace spine {
class String;
class SP_API SpineExtension {
public:
template <typename T>
static T *alloc(size_t num, const char *file, int line) {
return (T *)getInstance()->_alloc(sizeof(T) * num, file, line);
}
template <typename T>
static T *calloc(size_t num, const char *file, int line) {
return (T *)getInstance()->_calloc(sizeof(T) * num, file, line);
}
template <typename T>
static T *realloc(T *ptr, size_t num, const char *file, int line) {
return (T *)getInstance()->_realloc(ptr, sizeof(T) * num, file, line);
}
template <typename T>
static void free(T *ptr, const char *file, int line) {
getInstance()->_free((void *)ptr, file, line);
}
static char *readFile(const String &path, int *length) {
return getInstance()->_readFile(path, length);
}
static void setInstance(SpineExtension *inSpineExtension);
static SpineExtension *getInstance();
virtual ~SpineExtension();
/// Implement this function to use your own memory allocator
virtual void *_alloc(size_t size, const char *file, int line) = 0;
virtual void *_calloc(size_t size, const char *file, int line) = 0;
virtual void *_realloc(void *ptr, size_t size, const char *file, int line) = 0;
/// If you provide a spineAllocFunc, you should also provide a spineFreeFunc
virtual void _free(void *mem, const char *file, int line) = 0;
virtual char *_readFile(const String &path, int *length) = 0;
protected:
SpineExtension();
private:
static SpineExtension *_instance;
};
class SP_API DefaultSpineExtension : public SpineExtension {
public:
DefaultSpineExtension();
virtual ~DefaultSpineExtension();
protected:
virtual void *_alloc(size_t size, const char *file, int line);
virtual void *_calloc(size_t size, const char *file, int line);
virtual void *_realloc(void *ptr, size_t size, const char *file, int line);
virtual void _free(void *mem, const char *file, int line);
virtual char *_readFile(const String &path, int *length);
};
// This function is to be implemented by engine specific runtimes to provide
// the default extension for that engine. It is called the first time
// SpineExtension::getInstance() is called, when no instance has been set
// yet.
extern SpineExtension *getDefaultExtension();
} // namespace spine
#endif /* Spine_Extension_h */

View File

@@ -0,0 +1,65 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_HasRendererObject_h
#define Spine_HasRendererObject_h
#include "editor-support/spine/dll.h"
#include <cstdlib>
namespace spine {
typedef void (*DisposeRendererObject)(void* rendererObject);
class SP_API HasRendererObject {
public:
explicit HasRendererObject() : _rendererObject(NULL), _dispose(NULL){};
virtual ~HasRendererObject() {
if (_dispose && _rendererObject)
_dispose(_rendererObject);
}
void* getRendererObject() { return _rendererObject; }
void setRendererObject(void* rendererObject, DisposeRendererObject dispose = NULL) {
if (_dispose && _rendererObject && _rendererObject != rendererObject)
_dispose(_rendererObject);
_rendererObject = rendererObject;
_dispose = dispose;
}
private:
void* _rendererObject;
DisposeRendererObject _dispose;
};
} // namespace spine
#endif

View File

@@ -0,0 +1,192 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_HashMap_h
#define Spine_HashMap_h
#include <spine/Extension.h>
#include <spine/SpineObject.h>
#include <spine/Vector.h>
// Required for new with line number and file name in MSVC
#ifdef _MSC_VER
#pragma warning(disable : 4291)
#endif
namespace spine {
template <typename K, typename V>
class SP_API HashMap : public SpineObject {
private:
class Entry;
public:
class SP_API Pair {
public:
explicit Pair(K &k, V &v) : key(k), value(v) {}
K &key;
V &value;
};
class SP_API Entries {
public:
friend class HashMap;
explicit Entries(Entry *entry) : _entry(NULL), _hasChecked(false) {
_start.next = entry;
_entry = &_start;
}
Pair next() {
assert(_entry);
assert(_hasChecked);
_entry = _entry->next;
Pair pair(_entry->_key, _entry->_value);
_hasChecked = false;
return pair;
}
bool hasNext() {
_hasChecked = true;
return _entry->next;
}
private:
bool _hasChecked;
Entry _start;
Entry *_entry;
};
HashMap() : _head(NULL),
_size(0) {
}
~HashMap() {
clear();
}
void clear() {
for (Entry *entry = _head; entry != NULL;) {
Entry *next = entry->next;
delete entry;
entry = next;
}
_head = NULL;
_size = 0;
}
size_t size() {
return _size;
}
void put(const K &key, const V &value) {
Entry *entry = find(key);
if (entry) {
entry->_key = key;
entry->_value = value;
} else {
entry = new (__FILE__, __LINE__) Entry();
entry->_key = key;
entry->_value = value;
Entry *oldHead = _head;
if (oldHead) {
_head = entry;
oldHead->prev = entry;
entry->next = oldHead;
} else {
_head = entry;
}
_size++;
}
}
bool containsKey(const K &key) {
return find(key) != NULL;
}
bool remove(const K &key) {
Entry *entry = find(key);
if (!entry) return false;
Entry *prev = entry->prev;
Entry *next = entry->next;
if (prev)
prev->next = next;
else
_head = next;
if (next) next->prev = entry->prev;
delete entry;
_size--;
return true;
}
V operator[](const K &key) {
Entry *entry = find(key);
if (entry)
return entry->_value;
else {
assert(false);
return 0;
}
}
Entries getEntries() const {
return Entries(_head);
}
private:
Entry *find(const K &key) {
for (Entry *entry = _head; entry != NULL; entry = entry->next) {
if (entry->_key == key)
return entry;
}
return NULL;
}
class SP_API Entry : public SpineObject {
public:
K _key;
V _value;
Entry *next;
Entry *prev;
Entry() : next(NULL), prev(NULL) {}
};
Entry *_head;
size_t _size;
};
} // namespace spine
#endif /* Spine_HashMap_h */

View File

@@ -0,0 +1,359 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/IkConstraint.h>
#include <spine/Bone.h>
#include <spine/IkConstraintData.h>
#include <spine/Skeleton.h>
#include <spine/BoneData.h>
using namespace spine;
RTTI_IMPL(IkConstraint, Updatable)
void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress, bool stretch, bool uniform, float alpha) {
Bone *p = bone.getParent();
float pa = p->_a, pb = p->_b, pc = p->_c, pd = p->_d;
float rotationIK = -bone._ashearX - bone._arotation;
float tx = 0, ty = 0;
if (!bone._appliedValid) bone.updateAppliedTransform();
switch (bone._data.getTransformMode()) {
case TransformMode_OnlyTranslation:
tx = targetX - bone._worldX;
ty = targetY - bone._worldY;
break;
case TransformMode_NoRotationOrReflection: {
rotationIK += MathUtil::atan2(pc, pa) * MathUtil::Rad_Deg;
float ps = MathUtil::abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
pb = -pc * ps;
pd = pa * ps;
}
default:
float x = targetX - p->_worldX, y = targetY - p->_worldY;
float d = pa * pd - pb * pc;
tx = (x * pd - y * pb) / d - bone._ax;
ty = (y * pa - x * pc) / d - bone._ay;
}
rotationIK += MathUtil::atan2(ty, tx) * MathUtil::Rad_Deg;
if (bone._ascaleX < 0) rotationIK += 180;
if (rotationIK > 180)
rotationIK -= 360;
else if (rotationIK < -180)
rotationIK += 360;
float sx = bone._ascaleX;
float sy = bone._ascaleY;
if (compress || stretch) {
switch (bone._data.getTransformMode()) {
case TransformMode_NoScale:
case TransformMode_NoScaleOrReflection:
tx = targetX - bone._worldX;
ty = targetY - bone._worldY;
default:;
}
float b = bone._data.getLength() * sx, dd = MathUtil::sqrt(tx * tx + ty * ty);
if (((compress && dd < b) || (stretch && dd > b)) && (b > 0.0001f)) {
float s = (dd / b - 1) * alpha + 1;
sx *= s;
if (uniform) sy *= s;
}
}
bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, sx, sy, bone._ashearX, bone._ashearY);
}
void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY, int bendDir, bool stretch, float softness, float alpha) {
float a, b, c, d;
float px, py, psx, sx, psy;
float cx, cy, csx, cwx, cwy;
int o1, o2, s2, u;
Bone *pp = parent.getParent();
float tx, ty, dx, dy, dd, l1, l2, a1, a2, r, td, sd, p;
float id, x, y;
if (alpha == 0) {
child.updateWorldTransform();
return;
}
if (!parent._appliedValid) parent.updateAppliedTransform();
if (!child._appliedValid) child.updateAppliedTransform();
px = parent._ax;
py = parent._ay;
psx = parent._ascaleX;
sx = psx;
psy = parent._ascaleY;
csx = child._ascaleX;
if (psx < 0) {
psx = -psx;
o1 = 180;
s2 = -1;
} else {
o1 = 0;
s2 = 1;
}
if (psy < 0) {
psy = -psy;
s2 = -s2;
}
if (csx < 0) {
csx = -csx;
o2 = 180;
} else
o2 = 0;
r = psx - psy;
cx = child._ax;
u = (r < 0 ? -r : r) <= 0.0001f;
if (!u) {
cy = 0;
cwx = parent._a * cx + parent._worldX;
cwy = parent._c * cx + parent._worldY;
} else {
cy = child._ay;
cwx = parent._a * cx + parent._b * cy + parent._worldX;
cwy = parent._c * cx + parent._d * cy + parent._worldY;
}
a = pp->_a;
b = pp->_b;
c = pp->_c;
d = pp->_d;
id = 1 / (a * d - b * c);
x = cwx - pp->_worldX;
y = cwy - pp->_worldY;
dx = (x * d - y * b) * id - px;
dy = (y * a - x * c) * id - py;
l1 = MathUtil::sqrt(dx * dx + dy * dy);
l2 = child._data.getLength() * csx;
if (l1 < 0.0001) {
apply(parent, targetX, targetY, false, stretch, false, alpha);
child.updateWorldTransform(cx, cy, 0, child._ascaleX, child._ascaleY, child._ashearX, child._ashearY);
return;
}
x = targetX - pp->_worldX;
y = targetY - pp->_worldY;
tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;
dd = tx * tx + ty * ty;
if (softness != 0) {
softness *= psx * (csx + 1) / 2;
td = MathUtil::sqrt(dd), sd = td - l1 - l2 * psx + softness;
if (sd > 0) {
p = MathUtil::min(1.0f, sd / (softness * 2)) - 1;
p = (sd - softness * (1 - p * p)) / td;
tx -= p * tx;
ty -= p * ty;
dd = tx * tx + ty * ty;
}
}
if (u) {
float cosine;
l2 *= psx;
cosine = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2);
if (cosine < -1)
cosine = -1;
else if (cosine > 1) {
cosine = 1;
if (stretch) sx *= (MathUtil::sqrt(dd) / (l1 + l2) - 1) * alpha + 1;
}
a2 = MathUtil::acos(cosine) * bendDir;
a = l1 + l2 * cosine;
b = l2 * MathUtil::sin(a2);
a1 = MathUtil::atan2(ty * a - tx * b, tx * a + ty * b);
} else {
a = psx * l2, b = psy * l2;
float aa = a * a, bb = b * b, ll = l1 * l1, ta = MathUtil::atan2(ty, tx);
float c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa;
d = c1 * c1 - 4 * c2 * c0;
if (d >= 0) {
float q = MathUtil::sqrt(d), r0, r1;
if (c1 < 0) q = -q;
q = -(c1 + q) / 2;
r0 = q / c2;
r1 = c0 / q;
r = MathUtil::abs(r0) < MathUtil::abs(r1) ? r0 : r1;
if (r * r <= dd) {
y = MathUtil::sqrt(dd - r * r) * bendDir;
a1 = ta - MathUtil::atan2(y, r);
a2 = MathUtil::atan2(y / psy, (r - l1) / psx);
goto break_outer;
}
}
{
float minAngle = MathUtil::Pi, minX = l1 - a, minDist = minX * minX, minY = 0;
float maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
c0 = -a * l1 / (aa - bb);
if (c0 >= -1 && c0 <= 1) {
c0 = MathUtil::acos(c0);
x = a * MathUtil::cos(c0) + l1;
y = b * MathUtil::sin(c0);
d = x * x + y * y;
if (d < minDist) {
minAngle = c0;
minDist = d;
minX = x;
minY = y;
}
if (d > maxDist) {
maxAngle = c0;
maxDist = d;
maxX = x;
maxY = y;
}
}
if (dd <= (minDist + maxDist) / 2) {
a1 = ta - MathUtil::atan2(minY * bendDir, minX);
a2 = minAngle * bendDir;
} else {
a1 = ta - MathUtil::atan2(maxY * bendDir, maxX);
a2 = maxAngle * bendDir;
}
}
}
break_outer : {
float os = MathUtil::atan2(cy, cx) * s2;
a1 = (a1 - os) * MathUtil::Rad_Deg + o1 - parent._arotation;
if (a1 > 180)
a1 -= 360;
else if (a1 < -180)
a1 += 360;
parent.updateWorldTransform(px, py, parent._rotation + a1 * alpha, sx, parent._ascaleY, 0, 0);
a2 = ((a2 + os) * MathUtil::Rad_Deg - child._ashearX) * s2 + o2 - child._arotation;
if (a2 > 180)
a2 -= 360;
else if (a2 < -180)
a2 += 360;
child.updateWorldTransform(cx, cy, child._arotation + a2 * alpha, child._ascaleX, child._ascaleY, child._ashearX, child._ashearY);
}
}
IkConstraint::IkConstraint(IkConstraintData &data, Skeleton &skeleton) : Updatable(),
_data(data),
_bendDirection(data.getBendDirection()),
_compress(data.getCompress()),
_stretch(data.getStretch()),
_mix(data.getMix()),
_softness(data.getSoftness()),
_target(skeleton.findBone(
data.getTarget()->getName())),
_active(false) {
_bones.ensureCapacity(_data.getBones().size());
for (size_t i = 0; i < _data.getBones().size(); i++) {
BoneData *boneData = _data.getBones()[i];
_bones.add(skeleton.findBone(boneData->getName()));
}
}
/// Applies the constraint to the constrained bones.
void IkConstraint::apply() {
update();
}
void IkConstraint::update() {
switch (_bones.size()) {
case 1: {
Bone *bone0 = _bones[0];
apply(*bone0, _target->getWorldX(), _target->getWorldY(), _compress, _stretch, _data._uniform, _mix);
} break;
case 2: {
Bone *bone0 = _bones[0];
Bone *bone1 = _bones[1];
apply(*bone0, *bone1, _target->getWorldX(), _target->getWorldY(), _bendDirection, _stretch, _softness, _mix);
} break;
}
}
int IkConstraint::getOrder() {
return _data.getOrder();
}
IkConstraintData &IkConstraint::getData() {
return _data;
}
Vector<Bone *> &IkConstraint::getBones() {
return _bones;
}
Bone *IkConstraint::getTarget() {
return _target;
}
void IkConstraint::setTarget(Bone *inValue) {
_target = inValue;
}
int IkConstraint::getBendDirection() {
return _bendDirection;
}
void IkConstraint::setBendDirection(int inValue) {
_bendDirection = inValue;
}
float IkConstraint::getMix() {
return _mix;
}
void IkConstraint::setMix(float inValue) {
_mix = inValue;
}
bool IkConstraint::getStretch() {
return _stretch;
}
void IkConstraint::setStretch(bool inValue) {
_stretch = inValue;
}
bool IkConstraint::getCompress() {
return _compress;
}
void IkConstraint::setCompress(bool inValue) {
_compress = inValue;
}
bool IkConstraint::isActive() {
return _active;
}
void IkConstraint::setActive(bool inValue) {
_active = inValue;
}
float IkConstraint::getSoftness() {
return _softness;
}
void IkConstraint::setSoftness(float inValue) {
_softness = inValue;
}

View File

@@ -0,0 +1,115 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_IkConstraint_h
#define Spine_IkConstraint_h
#include <spine/ConstraintData.h>
#include <spine/Vector.h>
namespace spine {
class IkConstraintData;
class Skeleton;
class Bone;
class SP_API IkConstraint : public Updatable {
friend class Skeleton;
friend class IkConstraintTimeline;
RTTI_DECL
public:
/// Adjusts the bone rotation so the tip is as close to the target position as possible. The target is specified
/// in the world coordinate system.
static void apply(Bone &bone, float targetX, float targetY, bool compress, bool stretch, bool uniform, float alpha);
/// Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as
/// possible. The target is specified in the world coordinate system.
/// @param child A direct descendant of the parent bone.
static void apply(Bone &parent, Bone &child, float targetX, float targetY, int bendDir, bool stretch, float softness, float alpha);
IkConstraint(IkConstraintData &data, Skeleton &skeleton);
/// Applies the constraint to the constrained bones.
void apply();
virtual void update();
virtual int getOrder();
IkConstraintData &getData();
Vector<Bone *> &getBones();
Bone *getTarget();
void setTarget(Bone *inValue);
int getBendDirection();
void setBendDirection(int inValue);
bool getCompress();
void setCompress(bool inValue);
bool getStretch();
void setStretch(bool inValue);
float getMix();
void setMix(float inValue);
float getSoftness();
void setSoftness(float inValue);
bool isActive();
void setActive(bool inValue);
private:
IkConstraintData &_data;
Vector<Bone *> _bones;
int _bendDirection;
bool _compress;
bool _stretch;
float _mix;
float _softness;
Bone *_target;
bool _active;
};
} // namespace spine
#endif /* Spine_IkConstraint_h */

View File

@@ -0,0 +1,108 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/IkConstraintData.h>
#include <spine/BoneData.h>
using namespace spine;
IkConstraintData::IkConstraintData(const String &name) : ConstraintData(name),
_target(NULL),
_bendDirection(1),
_compress(false),
_stretch(false),
_uniform(false),
_mix(1),
_softness(0) {
}
Vector<BoneData *> &IkConstraintData::getBones() {
return _bones;
}
BoneData *IkConstraintData::getTarget() {
return _target;
}
void IkConstraintData::setTarget(BoneData *inValue) {
_target = inValue;
}
int IkConstraintData::getBendDirection() {
return _bendDirection;
}
void IkConstraintData::setBendDirection(int inValue) {
_bendDirection = inValue;
}
float IkConstraintData::getMix() {
return _mix;
}
void IkConstraintData::setMix(float inValue) {
_mix = inValue;
}
bool IkConstraintData::getStretch() {
return _stretch;
}
void IkConstraintData::setStretch(bool inValue) {
_stretch = inValue;
}
bool IkConstraintData::getCompress() {
return _compress;
}
void IkConstraintData::setCompress(bool inValue) {
_compress = inValue;
}
bool IkConstraintData::getUniform() {
return _uniform;
}
void IkConstraintData::setUniform(bool inValue) {
_uniform = inValue;
}
float IkConstraintData::getSoftness() {
return _softness;
}
void IkConstraintData::setSoftness(float inValue) {
_softness = inValue;
}

View File

@@ -0,0 +1,89 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_IkConstraintData_h
#define Spine_IkConstraintData_h
#include <spine/ConstraintData.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
#include <spine/Vector.h>
namespace spine {
class BoneData;
class SP_API IkConstraintData : public ConstraintData {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class IkConstraint;
friend class Skeleton;
friend class IkConstraintTimeline;
public:
explicit IkConstraintData(const String& name);
/// The bones that are constrained by this IK Constraint.
Vector<BoneData*>& getBones();
/// The bone that is the IK target.
BoneData* getTarget();
void setTarget(BoneData* inValue);
/// Controls the bend direction of the IK bones, either 1 or -1.
int getBendDirection();
void setBendDirection(int inValue);
bool getCompress();
void setCompress(bool inValue);
bool getStretch();
void setStretch(bool inValue);
bool getUniform();
void setUniform(bool inValue);
float getMix();
void setMix(float inValue);
float getSoftness();
void setSoftness(float inValue);
private:
Vector<BoneData*> _bones;
BoneData* _target;
int _bendDirection;
bool _compress;
bool _stretch;
bool _uniform;
float _mix;
float _softness;
};
} // namespace spine
#endif /* Spine_IkConstraintData_h */

View File

@@ -0,0 +1,168 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/IkConstraintTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/IkConstraint.h>
#include <spine/IkConstraintData.h>
#include <spine/Slot.h>
#include <spine/SlotData.h>
#include <spine/TimelineType.h>
using namespace spine;
RTTI_IMPL(IkConstraintTimeline, CurveTimeline)
const int IkConstraintTimeline::ENTRIES = 6;
const int IkConstraintTimeline::PREV_TIME = -6;
const int IkConstraintTimeline::PREV_MIX = -5;
const int IkConstraintTimeline::PREV_SOFTNESS = -4;
const int IkConstraintTimeline::PREV_BEND_DIRECTION = -3;
const int IkConstraintTimeline::PREV_COMPRESS = -2;
const int IkConstraintTimeline::PREV_STRETCH = -1;
const int IkConstraintTimeline::MIX = 1;
const int IkConstraintTimeline::SOFTNESS = 2;
const int IkConstraintTimeline::BEND_DIRECTION = 3;
const int IkConstraintTimeline::COMPRESS = 4;
const int IkConstraintTimeline::STRETCH = 5;
IkConstraintTimeline::IkConstraintTimeline(int frameCount) : CurveTimeline(frameCount), _ikConstraintIndex(0) {
_frames.setSize(frameCount * ENTRIES, 0);
}
void IkConstraintTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
IkConstraint *constraintP = skeleton._ikConstraints[_ikConstraintIndex];
IkConstraint &constraint = *constraintP;
if (!constraint.isActive()) return;
if (time < _frames[0]) {
switch (blend) {
case MixBlend_Setup:
constraint._mix = constraint._data._mix;
constraint._softness = constraint._data._softness;
constraint._bendDirection = constraint._data._bendDirection;
constraint._compress = constraint._data._compress;
constraint._stretch = constraint._data._stretch;
return;
case MixBlend_First:
constraint._mix += (constraint._data._mix - constraint._mix) * alpha;
constraint._softness += (constraint._data._softness - constraint._softness) * alpha;
constraint._bendDirection = constraint._data._bendDirection;
constraint._compress = constraint._data._compress;
constraint._stretch = constraint._data._stretch;
return;
default:
return;
}
}
if (time >= _frames[_frames.size() - ENTRIES]) {
// Time is after last frame.
if (blend == MixBlend_Setup) {
constraint._mix =
constraint._data._mix + (_frames[_frames.size() + PREV_MIX] - constraint._data._mix) * alpha;
constraint._softness = constraint._data._softness + (_frames[_frames.size() + PREV_SOFTNESS] - constraint._data._softness) * alpha;
if (direction == MixDirection_Out) {
constraint._bendDirection = constraint._data._bendDirection;
constraint._compress = constraint._data._compress;
constraint._stretch = constraint._data._stretch;
} else {
constraint._bendDirection = (int)_frames[_frames.size() + PREV_BEND_DIRECTION];
constraint._compress = _frames[_frames.size() + PREV_COMPRESS] != 0;
constraint._stretch = _frames[_frames.size() + PREV_STRETCH] != 0;
}
} else {
constraint._mix += (_frames[_frames.size() + PREV_MIX] - constraint._mix) * alpha;
constraint._softness += (_frames[_frames.size() + PREV_SOFTNESS] - constraint._softness) * alpha;
if (direction == MixDirection_In) {
constraint._bendDirection = (int)_frames[_frames.size() + PREV_BEND_DIRECTION];
constraint._compress = _frames[_frames.size() + PREV_COMPRESS] != 0;
constraint._stretch = _frames[_frames.size() + PREV_STRETCH] != 0;
}
}
return;
}
// Interpolate between the previous frame and the current frame.
int frame = Animation::binarySearch(_frames, time, ENTRIES);
float mix = _frames[frame + PREV_MIX];
float softness = _frames[frame + PREV_SOFTNESS];
float frameTime = _frames[frame];
float percent = getCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime));
if (blend == MixBlend_Setup) {
constraint._mix =
constraint._data._mix + (mix + (_frames[frame + MIX] - mix) * percent - constraint._data._mix) * alpha;
constraint._softness = constraint._data._softness + (softness + (_frames[frame + SOFTNESS] - softness) * percent - constraint._data._softness) * alpha;
if (direction == MixDirection_Out) {
constraint._bendDirection = constraint._data._bendDirection;
constraint._compress = constraint._data._compress;
constraint._stretch = constraint._data._stretch;
} else {
constraint._bendDirection = (int)_frames[_frames.size() + PREV_BEND_DIRECTION];
constraint._compress = _frames[frame + PREV_COMPRESS] != 0;
constraint._stretch = _frames[frame + PREV_STRETCH] != 0;
}
} else {
constraint._mix += (mix + (_frames[frame + MIX] - mix) * percent - constraint._mix) * alpha;
constraint._softness += (softness + (_frames[frame + SOFTNESS] - softness) * percent - constraint._softness) * alpha;
if (direction == MixDirection_In) {
constraint._bendDirection = (int)_frames[frame + PREV_BEND_DIRECTION];
constraint._compress = _frames[frame + PREV_COMPRESS] != 0;
constraint._stretch = _frames[frame + PREV_STRETCH] != 0;
}
}
}
int IkConstraintTimeline::getPropertyId() {
return ((int)TimelineType_IkConstraint << 24) + _ikConstraintIndex;
}
void IkConstraintTimeline::setFrame(int frameIndex, float time, float mix, float softness, int bendDirection, bool compress, bool stretch) {
frameIndex *= ENTRIES;
_frames[frameIndex] = time;
_frames[frameIndex + MIX] = mix;
_frames[frameIndex + SOFTNESS] = softness;
_frames[frameIndex + BEND_DIRECTION] = (float)bendDirection;
_frames[frameIndex + COMPRESS] = compress ? 1 : 0;
_frames[frameIndex + STRETCH] = stretch ? 1 : 0;
}

View File

@@ -0,0 +1,73 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_IkConstraintTimeline_h
#define Spine_IkConstraintTimeline_h
#include <spine/CurveTimeline.h>
namespace spine {
class SP_API IkConstraintTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
static const int ENTRIES;
explicit IkConstraintTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixBlend blend, MixDirection direction);
virtual int getPropertyId();
/// Sets the time, mix and bend direction of the specified keyframe.
void setFrame(int frameIndex, float time, float mix, float softness, int bendDirection, bool compress, bool stretch);
private:
static const int PREV_TIME;
static const int PREV_MIX;
static const int PREV_SOFTNESS;
static const int PREV_BEND_DIRECTION;
static const int PREV_COMPRESS;
static const int PREV_STRETCH;
static const int MIX;
static const int SOFTNESS;
static const int BEND_DIRECTION;
static const int COMPRESS;
static const int STRETCH;
Vector<float> _frames;
int _ikConstraintIndex;
};
} // namespace spine
#endif /* Spine_IkConstraintTimeline_h */

View File

@@ -0,0 +1,556 @@
/*
Copyright (c) 2009, Dave Gamble
Copyright (c) 2013, Esoteric Software
Permission is hereby granted, dispose 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:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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.
*/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
/* Json */
/* JSON parser in CPP, from json.c in the spine-c runtime */
#ifndef _DEFAULT_SOURCE
/* Bring strings.h definitions into string.h, where appropriate */
#define _DEFAULT_SOURCE
#endif
#ifndef _BSD_SOURCE
/* Bring strings.h definitions into string.h, where appropriate */
#define _BSD_SOURCE
#endif
#include <spine/Extension.h>
#include <spine/Json.h>
#include <spine/SpineString.h>
#include <assert.h>
#include <math.h>
using namespace spine;
const int Json::JSON_FALSE = 0;
const int Json::JSON_TRUE = 1;
const int Json::JSON_NULL = 2;
const int Json::JSON_NUMBER = 3;
const int Json::JSON_STRING = 4;
const int Json::JSON_ARRAY = 5;
const int Json::JSON_OBJECT = 6;
const char *Json::_error = NULL;
Json *Json::getItem(Json *object, const char *string) {
Json *c = object->_child;
while (c && json_strcasecmp(c->_name, string)) {
c = c->_next;
}
return c;
}
const char *Json::getString(Json *object, const char *name, const char *defaultValue) {
object = getItem(object, name);
if (object) {
return object->_valueString;
}
return defaultValue;
}
float Json::getFloat(Json *value, const char *name, float defaultValue) {
value = getItem(value, name);
return value ? value->_valueFloat : defaultValue;
}
int Json::getInt(Json *value, const char *name, int defaultValue) {
value = getItem(value, name);
return value ? value->_valueInt : defaultValue;
}
bool Json::getBoolean(spine::Json *value, const char *name, bool defaultValue) {
value = getItem(value, name);
if (value) {
if (value->_valueString) return strcmp(value->_valueString, "true") == 0;
if (value->_type == JSON_TRUE) return true;
if (value->_type == JSON_FALSE) return false;
if (value->_type == JSON_NULL) return false;
if (value->_type == JSON_NUMBER) return value->_valueFloat != 0;
return defaultValue;
} else {
return defaultValue;
}
}
const char *Json::getError() {
return _error;
}
Json::Json(const char *value) : _next(NULL),
#if SPINE_JSON_HAVE_PREV
_prev(NULL),
#endif
_child(NULL),
_type(0),
_size(0),
_valueString(NULL),
_valueInt(0),
_valueFloat(0),
_name(NULL) {
if (value) {
value = parseValue(this, skip(value));
assert(value);
}
}
Json::~Json() {
spine::Json *curr = nullptr;
spine::Json *next = _child;
do {
curr = next;
if (curr) {
next = curr->_next;
}
delete curr;
} while (next);
if (_valueString) {
SpineExtension::free(_valueString, __FILE__, __LINE__);
}
if (_name) {
SpineExtension::free(_name, __FILE__, __LINE__);
}
}
const char *Json::skip(const char *inValue) {
if (!inValue) {
/* must propagate NULL since it's often called in skip(f(...)) form */
return NULL;
}
while (*inValue && (unsigned char)*inValue <= 32) {
inValue++;
}
return inValue;
}
const char *Json::parseValue(Json *item, const char *value) {
/* Referenced by constructor, parseArray(), and parseObject(). */
/* Always called with the result of skip(). */
#ifdef SPINE_JSON_DEBUG /* Checked at entry to graph, constructor, and after every parse call. */
if (!value) {
/* Fail on null. */
return NULL;
}
#endif
switch (*value) {
case 'n': {
if (!strncmp(value + 1, "ull", 3)) {
item->_type = JSON_NULL;
return value + 4;
}
break;
}
case 'f': {
if (!strncmp(value + 1, "alse", 4)) {
item->_type = JSON_FALSE;
/* calloc prevents us needing item->_type = JSON_FALSE or valueInt = 0 here */
return value + 5;
}
break;
}
case 't': {
if (!strncmp(value + 1, "rue", 3)) {
item->_type = JSON_TRUE;
item->_valueInt = 1;
return value + 4;
}
break;
}
case '\"':
return parseString(item, value);
case '[':
return parseArray(item, value);
case '{':
return parseObject(item, value);
case '-': /* fallthrough */
case '0': /* fallthrough */
case '1': /* fallthrough */
case '2': /* fallthrough */
case '3': /* fallthrough */
case '4': /* fallthrough */
case '5': /* fallthrough */
case '6': /* fallthrough */
case '7': /* fallthrough */
case '8': /* fallthrough */
case '9':
return parseNumber(item, value);
default:
break;
}
_error = value;
return NULL; /* failure. */
}
static const unsigned char firstByteMark[7] = {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC};
const char *Json::parseString(Json *item, const char *str) {
const char *ptr = str + 1;
char *ptr2;
char *out;
int len = 0;
unsigned uc, uc2;
if (*str != '\"') {
/* TODO: don't need this check when called from parseValue, but do need from parseObject */
_error = str;
return 0;
} /* not a string! */
while (*ptr != '\"' && *ptr && ++len) {
if (*ptr++ == '\\') {
ptr++; /* Skip escaped quotes. */
}
}
out = SpineExtension::alloc<char>(len + 1, __FILE__, __LINE__); /* The length needed for the string, roughly. */
if (!out) {
return 0;
}
ptr = str + 1;
ptr2 = out;
while (*ptr != '\"' && *ptr) {
if (*ptr != '\\') {
*ptr2++ = *ptr++;
} else {
ptr++;
switch (*ptr) {
case 'b':
*ptr2++ = '\b';
break;
case 'f':
*ptr2++ = '\f';
break;
case 'n':
*ptr2++ = '\n';
break;
case 'r':
*ptr2++ = '\r';
break;
case 't':
*ptr2++ = '\t';
break;
case 'u': {
/* transcode utf16 to utf8. */
sscanf(ptr + 1, "%4x", &uc);
ptr += 4; /* get the unicode char. */
if ((uc >= 0xDC00 && uc <= 0xDFFF) || uc == 0) {
break; /* check for invalid. */
}
/* TODO provide an option to ignore surrogates, use unicode replacement character? */
if (uc >= 0xD800 && uc <= 0xDBFF) /* UTF16 surrogate pairs. */ {
if (ptr[1] != '\\' || ptr[2] != 'u') {
break; /* missing second-half of surrogate. */
}
sscanf(ptr + 3, "%4x", &uc2);
ptr += 6;
if (uc2 < 0xDC00 || uc2 > 0xDFFF) {
break; /* invalid second-half of surrogate. */
}
uc = 0x10000 + (((uc & 0x3FF) << 10) | (uc2 & 0x3FF));
}
len = 4;
if (uc < 0x80) {
len = 1;
} else if (uc < 0x800) {
len = 2;
} else if (uc < 0x10000) {
len = 3;
}
ptr2 += len;
switch (len) {
case 4:
*--ptr2 = ((uc | 0x80) & 0xBF);
uc >>= 6;
/* fallthrough */
case 3:
*--ptr2 = ((uc | 0x80) & 0xBF);
uc >>= 6;
/* fallthrough */
case 2:
*--ptr2 = ((uc | 0x80) & 0xBF);
uc >>= 6;
/* fallthrough */
case 1:
*--ptr2 = (uc | firstByteMark[len]);
}
ptr2 += len;
break;
}
default:
*ptr2++ = *ptr;
break;
}
ptr++;
}
}
*ptr2 = 0;
if (*ptr == '\"') {
ptr++; /* TODO error handling if not \" or \0 ? */
}
item->_valueString = out;
item->_type = JSON_STRING;
return ptr;
}
const char *Json::parseNumber(Json *item, const char *num) {
double result = 0.0;
int negative = 0;
char *ptr = (char *)num;
if (*ptr == '-') {
negative = -1;
++ptr;
}
while (*ptr >= '0' && *ptr <= '9') {
result = result * 10.0 + (*ptr - '0');
++ptr;
}
if (*ptr == '.') {
double fraction = 0.0;
int n = 0;
++ptr;
while (*ptr >= '0' && *ptr <= '9') {
fraction = (fraction * 10.0) + (*ptr - '0');
++ptr;
++n;
}
result += fraction / pow(10.0, n);
}
if (negative) {
result = -result;
}
if (*ptr == 'e' || *ptr == 'E') {
double exponent = 0;
int expNegative = 0;
int n = 0;
++ptr;
if (*ptr == '-') {
expNegative = -1;
++ptr;
} else if (*ptr == '+') {
++ptr;
}
while (*ptr >= '0' && *ptr <= '9') {
exponent = (exponent * 10.0) + (*ptr - '0');
++ptr;
++n;
}
if (expNegative) {
result = result / pow(10, exponent);
} else {
result = result * pow(10, exponent);
}
}
if (ptr != num) {
/* Parse success, number found. */
item->_valueFloat = (float)result;
item->_valueInt = (int)result;
item->_type = JSON_NUMBER;
return ptr;
} else {
/* Parse failure, _error is set. */
_error = num;
return NULL;
}
}
const char *Json::parseArray(Json *item, const char *value) {
Json *child;
#ifdef SPINE_JSON_DEBUG /* unnecessary, only callsite (parse_value) verifies this */
if (*value != '[') {
ep = value;
return 0;
} /* not an array! */
#endif
item->_type = JSON_ARRAY;
value = skip(value + 1);
if (*value == ']') {
return value + 1; /* empty array. */
}
item->_child = child = new Json(NULL);
if (!item->_child) {
return NULL; /* memory fail */
}
value = skip(parseValue(child, skip(value))); /* skip any spacing, get the value. */
if (!value) {
return NULL;
}
item->_size = 1;
while (*value == ',') {
Json *new_item = new Json(NULL);
if (!new_item) {
return NULL; /* memory fail */
}
child->_next = new_item;
#if SPINE_JSON_HAVE_PREV
new_item->prev = child;
#endif
child = new_item;
value = skip(parseValue(child, skip(value + 1)));
if (!value) {
return NULL; /* parse fail */
}
item->_size++;
}
if (*value == ']') {
return value + 1; /* end of array */
}
_error = value;
return NULL; /* malformed. */
}
/* Build an object from the text. */
const char *Json::parseObject(Json *item, const char *value) {
Json *child;
#ifdef SPINE_JSON_DEBUG /* unnecessary, only callsite (parse_value) verifies this */
if (*value != '{') {
ep = value;
return 0;
} /* not an object! */
#endif
item->_type = JSON_OBJECT;
value = skip(value + 1);
if (*value == '}') {
return value + 1; /* empty array. */
}
item->_child = child = new Json(NULL);
if (!item->_child) {
return NULL;
}
value = skip(parseString(child, skip(value)));
if (!value) {
return NULL;
}
child->_name = child->_valueString;
child->_valueString = 0;
if (*value != ':') {
_error = value;
return NULL;
} /* fail! */
value = skip(parseValue(child, skip(value + 1))); /* skip any spacing, get the value. */
if (!value) {
return NULL;
}
item->_size = 1;
while (*value == ',') {
Json *new_item = new Json(NULL);
if (!new_item) {
return NULL; /* memory fail */
}
child->_next = new_item;
#if SPINE_JSON_HAVE_PREV
new_item->prev = child;
#endif
child = new_item;
value = skip(parseString(child, skip(value + 1)));
if (!value) {
return NULL;
}
child->_name = child->_valueString;
child->_valueString = 0;
if (*value != ':') {
_error = value;
return NULL;
} /* fail! */
value = skip(parseValue(child, skip(value + 1))); /* skip any spacing, get the value. */
if (!value) {
return NULL;
}
item->_size++;
}
if (*value == '}') {
return value + 1; /* end of array */
}
_error = value;
return NULL; /* malformed. */
}
int Json::json_strcasecmp(const char *s1, const char *s2) {
/* TODO we may be able to elide these NULL checks if we can prove
* the graph and input (only callsite is Json_getItem) should not have NULLs
*/
if (s1 && s2) {
#if defined(_WIN32)
return _stricmp(s1, s2);
#else
return strcasecmp(s1, s2);
#endif
} else {
if (s1 < s2) {
return -1; /* s1 is null, s2 is not */
} else if (s1 == s2) {
return 0; /* both are null */
} else {
return 1; /* s2 is nul s1 is not */
}
}
}

View File

@@ -0,0 +1,113 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_Json_h
#define Spine_Json_h
#include <spine/SpineObject.h>
#ifndef SPINE_JSON_HAVE_PREV
/* spine doesn't use the "prev" link in the Json sibling lists. */
#define SPINE_JSON_HAVE_PREV 0
#endif
namespace spine {
class SP_API Json {
friend class SkeletonJson;
public:
/* Json Types: */
static const int JSON_FALSE;
static const int JSON_TRUE;
static const int JSON_NULL;
static const int JSON_NUMBER;
static const int JSON_STRING;
static const int JSON_ARRAY;
static const int JSON_OBJECT;
/* Get item "string" from object. Case insensitive. */
static Json *getItem(Json *object, const char *string);
static const char *getString(Json *object, const char *name, const char *defaultValue);
static float getFloat(Json *object, const char *name, float defaultValue);
static int getInt(Json *object, const char *name, int defaultValue);
static bool getBoolean(Json *object, const char *name, bool defaultValue);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when Json_create() returns 0. 0 when Json_create() succeeds. */
static const char *getError();
/* Supply a block of JSON, and this returns a Json object you can interrogate. Call Json_dispose when finished. */
explicit Json(const char *value);
~Json();
private:
static const char *_error;
Json *_next;
#if SPINE_JSON_HAVE_PREV
Json *_prev; /* next/prev allow you to walk array/object chains. Alternatively, use getSize/getItem */
#endif
Json *_child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
int _type; /* The type of the item, as above. */
int _size; /* The number of children. */
const char *_valueString; /* The item's string, if type==JSON_STRING */
int _valueInt; /* The item's number, if type==JSON_NUMBER */
float _valueFloat; /* The item's number, if type==JSON_NUMBER */
const char *_name; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
/* Utility to jump whitespace and cr/lf */
static const char *skip(const char *inValue);
/* Parser core - when encountering text, process appropriately. */
static const char *parseValue(Json *item, const char *value);
/* Parse the input text into an unescaped cstring, and populate item. */
static const char *parseString(Json *item, const char *str);
/* Parse the input text to generate a number, and populate the result into item. */
static const char *parseNumber(Json *item, const char *num);
/* Build an array from input text. */
static const char *parseArray(Json *item, const char *value);
/* Build an object from the text. */
static const char *parseObject(Json *item, const char *value);
static int json_strcasecmp(const char *s1, const char *s2);
};
} // namespace spine
#endif /* Spine_Json_h */

View File

@@ -0,0 +1,45 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/LinkedMesh.h>
#include <spine/MeshAttachment.h>
using namespace spine;
LinkedMesh::LinkedMesh(MeshAttachment *mesh, const String &skin, size_t slotIndex, const String &parent, bool inheritDeform) : _mesh(mesh),
_skin(skin),
_slotIndex(slotIndex),
_parent(parent),
_inheritDeform(inheritDeform) {
}

View File

@@ -0,0 +1,56 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_LinkedMesh_h
#define Spine_LinkedMesh_h
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
namespace spine {
class MeshAttachment;
class SP_API LinkedMesh : public SpineObject {
friend class SkeletonBinary;
friend class SkeletonJson;
public:
LinkedMesh(MeshAttachment *mesh, const String &skin, size_t slotIndex, const String &parent, bool inheritDeform);
private:
MeshAttachment *_mesh;
String _skin;
size_t _slotIndex;
String _parent;
bool _inheritDeform;
};
} // namespace spine
#endif /* Spine_LinkedMesh_h */

View File

@@ -0,0 +1,128 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <math.h>
#include <spine/MathUtil.h>
#include <stdlib.h>
// Required for division by 0 in _isNaN on MSVC
#ifdef _MSC_VER
#pragma warning(disable : 4723)
#endif
using namespace spine;
const float MathUtil::Pi = 3.1415926535897932385f;
const float MathUtil::Pi_2 = 3.1415926535897932385f * 2;
const float MathUtil::Deg_Rad = (3.1415926535897932385f / 180.0f);
const float MathUtil::Rad_Deg = (180.0f / 3.1415926535897932385f);
float MathUtil::abs(float v) {
return ((v) < 0 ? -(v) : (v));
}
float MathUtil::sign(float v) {
return ((v) < 0 ? -1.0f : (v) > 0 ? 1.0f
: 0.0f);
}
float MathUtil::clamp(float x, float min, float max) {
return ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)));
}
float MathUtil::fmod(float a, float b) {
return (float)::fmod(a, b);
}
/// Returns atan2 in radians, faster but less accurate than Math.Atan2. Average error of 0.00231 radians (0.1323
/// degrees), largest error of 0.00488 radians (0.2796 degrees).
float MathUtil::atan2(float y, float x) {
return (float)::atan2(y, x);
}
/// Returns the cosine in radians from a lookup table.
float MathUtil::cos(float radians) {
return (float)::cos(radians);
}
/// Returns the sine in radians from a lookup table.
float MathUtil::sin(float radians) {
return (float)::sin(radians);
}
float MathUtil::sqrt(float v) {
return (float)::sqrt(v);
}
float MathUtil::acos(float v) {
return (float)::acos(v);
}
/// Returns the sine in radians from a lookup table.
float MathUtil::sinDeg(float degrees) {
return (float)::sin(degrees * MathUtil::Deg_Rad);
}
/// Returns the cosine in radians from a lookup table.
float MathUtil::cosDeg(float degrees) {
return (float)::cos(degrees * MathUtil::Deg_Rad);
}
/* Need to pass 0 as an argument, so VC++ doesn't error with C2124 */
static bool _isNan(float value, float zero) {
float _nan = (float)0.0 / zero;
return 0 == memcmp((void *)&value, (void *)&_nan, sizeof(value));
}
bool MathUtil::isNan(float v) {
return _isNan(v, 0);
}
float MathUtil::random() {
return ::rand() / (float)RAND_MAX;
}
float MathUtil::randomTriangular(float min, float max) {
return randomTriangular(min, max, (min + max) * 0.5f);
}
float MathUtil::randomTriangular(float min, float max, float mode) {
float u = random();
float d = max - min;
if (u <= (mode - min) / d) return min + sqrt(u * d * (mode - min));
return max - sqrt((1 - u) * d * (max - mode));
}
float MathUtil::pow(float a, float b) {
return (float)::pow(a, b);
}

View File

@@ -0,0 +1,129 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_MathUtil_h
#define Spine_MathUtil_h
#include <spine/SpineObject.h>
#include <string.h>
namespace spine {
class SP_API MathUtil : public SpineObject {
private:
MathUtil();
public:
static const float Pi;
static const float Pi_2;
static const float Deg_Rad;
static const float Rad_Deg;
template <typename T>
static inline T min(T a, T b) { return a < b ? a : b; }
template <typename T>
static inline T max(T a, T b) { return a > b ? a : b; }
static float sign(float val);
static float clamp(float x, float lower, float upper);
static float abs(float v);
/// Returns the sine in radians from a lookup table.
static float sin(float radians);
/// Returns the cosine in radians from a lookup table.
static float cos(float radians);
/// Returns the sine in radians from a lookup table.
static float sinDeg(float degrees);
/// Returns the cosine in radians from a lookup table.
static float cosDeg(float degrees);
/// Returns atan2 in radians, faster but less accurate than Math.Atan2. Average error of 0.00231 radians (0.1323
/// degrees), largest error of 0.00488 radians (0.2796 degrees).
static float atan2(float y, float x);
static float acos(float v);
static float sqrt(float v);
static float fmod(float a, float b);
static bool isNan(float v);
static float random();
static float randomTriangular(float min, float max);
static float randomTriangular(float min, float max, float mode);
static float pow(float a, float b);
};
struct SP_API Interpolation {
virtual float apply(float a) = 0;
virtual float interpolate(float start, float end, float a) {
return start + (end - start) * apply(a);
}
virtual ~Interpolation(){};
};
struct SP_API PowInterpolation : public Interpolation {
PowInterpolation(int power) : power(power) {
}
float apply(float a) {
if (a <= 0.5f) return MathUtil::pow(a * 2.0f, (float)power) / 2.0f;
return MathUtil::pow((a - 1.0f) * 2.0f, (float)power) / (power % 2 == 0 ? -2.0f : 2.0f) + 1.0f;
}
int power;
};
struct SP_API PowOutInterpolation : public Interpolation {
PowOutInterpolation(int power) : power(power) {
}
float apply(float a) {
return MathUtil::pow(a - 1, (float)power) * (power % 2 == 0 ? -1.0f : 1.0f) + 1.0f;
}
int power;
};
} // namespace spine
#endif /* Spine_MathUtil_h */

View File

@@ -0,0 +1,330 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/HasRendererObject.h>
#include <spine/MeshAttachment.h>
using namespace spine;
RTTI_IMPL(MeshAttachment, VertexAttachment)
MeshAttachment::MeshAttachment(const String &name) : VertexAttachment(name), HasRendererObject(), _regionOffsetX(0), _regionOffsetY(0), _regionWidth(0), _regionHeight(0), _regionOriginalWidth(0), _regionOriginalHeight(0), _parentMesh(NULL), _path(), _regionU(0), _regionV(0), _regionU2(0), _regionV2(0), _width(0), _height(0), _color(1, 1, 1, 1), _hullLength(0), _regionRotate(false), _regionDegrees(0) {}
MeshAttachment::~MeshAttachment() {}
void MeshAttachment::updateUVs() {
if (_uvs.size() != _regionUVs.size()) {
_uvs.setSize(_regionUVs.size(), 0);
}
int i = 0, n = _regionUVs.size();
float u = _regionU, v = _regionV;
float width = 0, height = 0;
switch (_regionDegrees) {
case 90: {
float textureWidth = _regionHeight / (_regionU2 - _regionU);
float textureHeight = _regionWidth / (_regionV2 - _regionV);
u -= (_regionOriginalHeight - _regionOffsetY - _regionHeight) / textureWidth;
v -= (_regionOriginalWidth - _regionOffsetX - _regionWidth) / textureHeight;
width = _regionOriginalHeight / textureWidth;
height = _regionOriginalWidth / textureHeight;
for (i = 0; i < n; i += 2) {
_uvs[i] = u + _regionUVs[i + 1] * width;
_uvs[i + 1] = v + (1 - _regionUVs[i]) * height;
}
return;
}
case 180: {
float textureWidth = _regionWidth / (_regionU2 - _regionU);
float textureHeight = _regionHeight / (_regionV2 - _regionV);
u -= (_regionOriginalWidth - _regionOffsetX - _regionWidth) / textureWidth;
v -= _regionOffsetY / textureHeight;
width = _regionOriginalWidth / textureWidth;
height = _regionOriginalHeight / textureHeight;
for (i = 0; i < n; i += 2) {
_uvs[i] = u + (1 - _regionUVs[i]) * width;
_uvs[i + 1] = v + (1 - _regionUVs[i + 1]) * height;
}
return;
}
case 270: {
float textureHeight = _regionHeight / (_regionV2 - _regionV);
float textureWidth = _regionWidth / (_regionU2 - _regionU);
u -= _regionOffsetY / textureWidth;
v -= _regionOffsetX / textureHeight;
width = _regionOriginalHeight / textureWidth;
height = _regionOriginalWidth / textureHeight;
for (i = 0; i < n; i += 2) {
_uvs[i] = u + (1 - _regionUVs[i + 1]) * width;
_uvs[i + 1] = v + _regionUVs[i] * height;
}
return;
}
default: {
float textureWidth = _regionWidth / (_regionU2 - _regionU);
float textureHeight = _regionHeight / (_regionV2 - _regionV);
u -= _regionOffsetX / textureWidth;
v -= (_regionOriginalHeight - _regionOffsetY - _regionHeight) / textureHeight;
width = _regionOriginalWidth / textureWidth;
height = _regionOriginalHeight / textureHeight;
for (i = 0; i < n; i += 2) {
_uvs[i] = u + _regionUVs[i] * width;
_uvs[i + 1] = v + _regionUVs[i + 1] * height;
}
}
}
}
int MeshAttachment::getHullLength() {
return _hullLength;
}
void MeshAttachment::setHullLength(int inValue) {
_hullLength = inValue;
}
Vector<float> &MeshAttachment::getRegionUVs() {
return _regionUVs;
}
Vector<float> &MeshAttachment::getUVs() {
return _uvs;
}
Vector<unsigned short> &MeshAttachment::getTriangles() {
return _triangles;
}
const String &MeshAttachment::getPath() {
return _path;
}
void MeshAttachment::setPath(const String &inValue) {
_path = inValue;
}
float MeshAttachment::getRegionU() {
return _regionU;
}
void MeshAttachment::setRegionU(float inValue) {
_regionU = inValue;
}
float MeshAttachment::getRegionV() {
return _regionV;
}
void MeshAttachment::setRegionV(float inValue) {
_regionV = inValue;
}
float MeshAttachment::getRegionU2() {
return _regionU2;
}
void MeshAttachment::setRegionU2(float inValue) {
_regionU2 = inValue;
}
float MeshAttachment::getRegionV2() {
return _regionV2;
}
void MeshAttachment::setRegionV2(float inValue) {
_regionV2 = inValue;
}
bool MeshAttachment::getRegionRotate() {
return _regionRotate;
}
void MeshAttachment::setRegionRotate(bool inValue) {
_regionRotate = inValue;
}
int MeshAttachment::getRegionDegrees() {
return _regionDegrees;
}
void MeshAttachment::setRegionDegrees(int inValue) {
_regionDegrees = inValue;
}
float MeshAttachment::getRegionOffsetX() {
return _regionOffsetX;
}
void MeshAttachment::setRegionOffsetX(float inValue) {
_regionOffsetX = inValue;
}
float MeshAttachment::getRegionOffsetY() {
return _regionOffsetY;
}
void MeshAttachment::setRegionOffsetY(float inValue) {
_regionOffsetY = inValue;
}
float MeshAttachment::getRegionWidth() {
return _regionWidth;
}
void MeshAttachment::setRegionWidth(float inValue) {
_regionWidth = inValue;
}
float MeshAttachment::getRegionHeight() {
return _regionHeight;
}
void MeshAttachment::setRegionHeight(float inValue) {
_regionHeight = inValue;
}
float MeshAttachment::getRegionOriginalWidth() {
return _regionOriginalWidth;
}
void MeshAttachment::setRegionOriginalWidth(float inValue) {
_regionOriginalWidth = inValue;
}
float MeshAttachment::getRegionOriginalHeight() {
return _regionOriginalHeight;
}
void MeshAttachment::setRegionOriginalHeight(float inValue) {
_regionOriginalHeight = inValue;
}
MeshAttachment *MeshAttachment::getParentMesh() {
return _parentMesh;
}
void MeshAttachment::setParentMesh(MeshAttachment *inValue) {
_parentMesh = inValue;
if (inValue != NULL) {
_bones.clearAndAddAll(inValue->_bones);
_vertices.clearAndAddAll(inValue->_vertices);
_worldVerticesLength = inValue->_worldVerticesLength;
_regionUVs.clearAndAddAll(inValue->_regionUVs);
_triangles.clearAndAddAll(inValue->_triangles);
_hullLength = inValue->_hullLength;
_edges.clearAndAddAll(inValue->_edges);
_width = inValue->_width;
_height = inValue->_height;
}
}
Vector<unsigned short> &MeshAttachment::getEdges() {
return _edges;
}
float MeshAttachment::getWidth() {
return _width;
}
void MeshAttachment::setWidth(float inValue) {
_width = inValue;
}
float MeshAttachment::getHeight() {
return _height;
}
void MeshAttachment::setHeight(float inValue) {
_height = inValue;
}
spine::Color &MeshAttachment::getColor() {
return _color;
}
Attachment *MeshAttachment::copy() {
if (_parentMesh) return newLinkedMesh();
MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName());
copy->setRendererObject(getRendererObject());
copy->_regionU = _regionU;
copy->_regionV = _regionV;
copy->_regionU2 = _regionU2;
copy->_regionV2 = _regionV2;
copy->_regionRotate = _regionRotate;
copy->_regionDegrees = _regionDegrees;
copy->_regionOffsetX = _regionOffsetX;
copy->_regionOffsetY = _regionOffsetY;
copy->_regionWidth = _regionWidth;
copy->_regionHeight = _regionHeight;
copy->_regionOriginalWidth = _regionOriginalWidth;
copy->_regionOriginalHeight = _regionOriginalHeight;
copy->_path = _path;
copy->_color.set(_color);
copyTo(copy);
copy->_regionUVs.clearAndAddAll(_regionUVs);
copy->_uvs.clearAndAddAll(_uvs);
copy->_triangles.clearAndAddAll(_triangles);
copy->_hullLength = _hullLength;
// Nonessential.
copy->_edges.clearAndAddAll(copy->_edges);
copy->_width = _width;
copy->_height = _height;
return copy;
}
MeshAttachment *MeshAttachment::newLinkedMesh() {
MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName());
copy->setRendererObject(getRendererObject());
copy->_regionU = _regionU;
copy->_regionV = _regionV;
copy->_regionU2 = _regionU2;
copy->_regionV2 = _regionV2;
copy->_regionRotate = _regionRotate;
copy->_regionDegrees = _regionDegrees;
copy->_regionOffsetX = _regionOffsetX;
copy->_regionOffsetY = _regionOffsetY;
copy->_regionWidth = _regionWidth;
copy->_regionHeight = _regionHeight;
copy->_regionOriginalWidth = _regionOriginalWidth;
copy->_regionOriginalHeight = _regionOriginalHeight;
copy->_path = _path;
copy->_color.set(_color);
copy->_deformAttachment = this->_deformAttachment;
copy->setParentMesh(_parentMesh ? _parentMesh : this);
copy->updateUVs();
return copy;
}

View File

@@ -0,0 +1,143 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_MeshAttachment_h
#define Spine_MeshAttachment_h
#include <spine/Color.h>
#include <spine/HasRendererObject.h>
#include <spine/Vector.h>
#include <spine/VertexAttachment.h>
namespace spine {
/// Attachment that displays a texture region using a mesh.
class SP_API MeshAttachment : public VertexAttachment, public HasRendererObject {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class AtlasAttachmentLoader;
RTTI_DECL
public:
explicit MeshAttachment(const String& name);
virtual ~MeshAttachment();
void updateUVs();
int getHullLength();
void setHullLength(int inValue);
Vector<float>& getRegionUVs();
/// The UV pair for each vertex, normalized within the entire texture. See also MeshAttachment::updateUVs
Vector<float>& getUVs();
Vector<unsigned short>& getTriangles();
Color& getColor();
const String& getPath();
void setPath(const String& inValue);
float getRegionU();
void setRegionU(float inValue);
float getRegionV();
void setRegionV(float inValue);
float getRegionU2();
void setRegionU2(float inValue);
float getRegionV2();
void setRegionV2(float inValue);
bool getRegionRotate();
void setRegionRotate(bool inValue);
int getRegionDegrees();
void setRegionDegrees(int inValue);
float getRegionOffsetX();
void setRegionOffsetX(float inValue);
// Pixels stripped from the bottom left, unrotated.
float getRegionOffsetY();
void setRegionOffsetY(float inValue);
float getRegionWidth();
void setRegionWidth(float inValue);
// Unrotated, stripped size.
float getRegionHeight();
void setRegionHeight(float inValue);
float getRegionOriginalWidth();
void setRegionOriginalWidth(float inValue);
// Unrotated, unstripped size.
float getRegionOriginalHeight();
void setRegionOriginalHeight(float inValue);
MeshAttachment* getParentMesh();
void setParentMesh(MeshAttachment* inValue);
// Nonessential.
Vector<unsigned short>& getEdges();
float getWidth();
void setWidth(float inValue);
float getHeight();
void setHeight(float inValue);
virtual Attachment* copy();
MeshAttachment* newLinkedMesh();
private:
float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight;
MeshAttachment* _parentMesh;
Vector<float> _uvs;
Vector<float> _regionUVs;
Vector<unsigned short> _triangles;
Vector<unsigned short> _edges;
String _path;
float _regionU;
float _regionV;
float _regionU2;
float _regionV2;
float _width;
float _height;
Color _color;
int _hullLength;
bool _regionRotate;
int _regionDegrees;
};
} // namespace spine
#endif /* Spine_MeshAttachment_h */

View File

@@ -0,0 +1,45 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_MixPose_h
#define Spine_MixPose_h
namespace spine {
/// Controls how a timeline is mixed with the setup or current pose.
/// See also Timeline::apply(Skeleton&, float, float, Vector&, float, Blend, MixDirection)
enum MixBlend {
MixBlend_Setup = 0,
MixBlend_First,
MixBlend_Replace,
MixBlend_Add
};
} // namespace spine
#endif /* Spine_MixPose_h */

View File

@@ -0,0 +1,44 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_MixDirection_h
#define Spine_MixDirection_h
namespace spine {
/// Indicates whether a timeline's alpha is mixing out over time toward 0 (the setup or current pose) or mixing in toward 1 (the timeline's pose).
/// See also Timeline::apply(Skeleton&, float, float, Vector&, float, MixPose, MixDirection)
enum MixDirection {
MixDirection_In = 0,
MixDirection_Out
};
} // namespace spine
#endif /* Spine_MixDirection_h */

View File

@@ -0,0 +1,70 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/PathAttachment.h>
using namespace spine;
RTTI_IMPL(PathAttachment, VertexAttachment)
PathAttachment::PathAttachment(const String& name) : VertexAttachment(name), _closed(false), _constantSpeed(false) {
}
Vector<float>& PathAttachment::getLengths() {
return _lengths;
}
bool PathAttachment::isClosed() {
return _closed;
}
void PathAttachment::setClosed(bool inValue) {
_closed = inValue;
}
bool PathAttachment::isConstantSpeed() {
return _constantSpeed;
}
void PathAttachment::setConstantSpeed(bool inValue) {
_constantSpeed = inValue;
}
Attachment* PathAttachment::copy() {
PathAttachment* copy = new (__FILE__, __LINE__) PathAttachment(getName());
copyTo(copy);
copy->_lengths.clearAndAddAll(_lengths);
copy->_closed = _closed;
copy->_constantSpeed = _constantSpeed;
return copy;
}

View File

@@ -0,0 +1,61 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_PathAttachment_h
#define Spine_PathAttachment_h
#include <spine/VertexAttachment.h>
namespace spine {
class SP_API PathAttachment : public VertexAttachment {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
explicit PathAttachment(const String& name);
/// The length in the setup pose from the start of the path to the end of each curve.
Vector<float>& getLengths();
bool isClosed();
void setClosed(bool inValue);
bool isConstantSpeed();
void setConstantSpeed(bool inValue);
virtual Attachment* copy();
private:
Vector<float> _lengths;
bool _closed;
bool _constantSpeed;
};
} // namespace spine
#endif /* Spine_PathAttachment_h */

View File

@@ -0,0 +1,547 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/PathConstraint.h>
#include <spine/Bone.h>
#include <spine/PathAttachment.h>
#include <spine/PathConstraintData.h>
#include <spine/Skeleton.h>
#include <spine/Slot.h>
#include <spine/BoneData.h>
#include <spine/SlotData.h>
using namespace spine;
RTTI_IMPL(PathConstraint, Updatable)
const float PathConstraint::EPSILON = 0.00001f;
const int PathConstraint::NONE = -1;
const int PathConstraint::BEFORE = -2;
const int PathConstraint::AFTER = -3;
PathConstraint::PathConstraint(PathConstraintData &data, Skeleton &skeleton) : Updatable(),
_data(data),
_target(skeleton.findSlot(
data.getTarget()->getName())),
_position(data.getPosition()),
_spacing(data.getSpacing()),
_rotateMix(data.getRotateMix()),
_translateMix(data.getTranslateMix()),
_active(false) {
_bones.ensureCapacity(_data.getBones().size());
for (size_t i = 0; i < _data.getBones().size(); i++) {
BoneData *boneData = _data.getBones()[i];
_bones.add(skeleton.findBone(boneData->getName()));
}
_segments.setSize(10, 0);
}
void PathConstraint::apply() {
update();
}
void PathConstraint::update() {
Attachment *baseAttachment = _target->getAttachment();
if (baseAttachment == NULL || !baseAttachment->getRTTI().instanceOf(PathAttachment::rtti)) {
return;
}
PathAttachment *attachment = static_cast<PathAttachment *>(baseAttachment);
float rotateMix = _rotateMix;
float translateMix = _translateMix;
bool translate = translateMix > 0;
bool rotate = rotateMix > 0;
if (!translate && !rotate) {
return;
}
PathConstraintData &data = _data;
bool percentSpacing = data._spacingMode == SpacingMode_Percent;
RotateMode rotateMode = data._rotateMode;
bool tangents = rotateMode == RotateMode_Tangent, scale = rotateMode == RotateMode_ChainScale;
size_t boneCount = _bones.size();
size_t spacesCount = tangents ? boneCount : boneCount + 1;
_spaces.setSize(spacesCount, 0);
float spacing = _spacing;
if (scale || !percentSpacing) {
if (scale) _lengths.setSize(boneCount, 0);
bool lengthSpacing = data._spacingMode == SpacingMode_Length;
for (size_t i = 0, n = spacesCount - 1; i < n;) {
Bone *boneP = _bones[i];
Bone &bone = *boneP;
float setupLength = bone._data.getLength();
if (setupLength < PathConstraint::EPSILON) {
if (scale) _lengths[i] = 0;
_spaces[++i] = 0;
} else if (percentSpacing) {
if (scale) {
float x = setupLength * bone._a, y = setupLength * bone._c;
float length = MathUtil::sqrt(x * x + y * y);
_lengths[i] = length;
}
_spaces[++i] = spacing;
} else {
float x = setupLength * bone._a;
float y = setupLength * bone._c;
float length = MathUtil::sqrt(x * x + y * y);
if (scale) {
_lengths[i] = length;
}
_spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength;
}
}
} else {
for (size_t i = 1; i < spacesCount; ++i) {
_spaces[i] = spacing;
}
}
Vector<float> &positions = computeWorldPositions(*attachment, spacesCount, tangents,
data.getPositionMode() == PositionMode_Percent, percentSpacing);
float boneX = positions[0];
float boneY = positions[1];
float offsetRotation = data.getOffsetRotation();
bool tip;
if (offsetRotation == 0) {
tip = rotateMode == RotateMode_Chain;
} else {
tip = false;
Bone &p = _target->getBone();
offsetRotation *= p.getA() * p.getD() - p.getB() * p.getC() > 0 ? MathUtil::Deg_Rad : -MathUtil::Deg_Rad;
}
for (size_t i = 0, p = 3; i < boneCount; i++, p += 3) {
Bone *boneP = _bones[i];
Bone &bone = *boneP;
bone._worldX += (boneX - bone._worldX) * translateMix;
bone._worldY += (boneY - bone._worldY) * translateMix;
float x = positions[p];
float y = positions[p + 1];
float dx = x - boneX;
float dy = y - boneY;
if (scale) {
float length = _lengths[i];
if (length >= PathConstraint::EPSILON) {
float s = (MathUtil::sqrt(dx * dx + dy * dy) / length - 1) * rotateMix + 1;
bone._a *= s;
bone._c *= s;
}
}
boneX = x;
boneY = y;
if (rotate) {
float a = bone._a, b = bone._b, c = bone._c, d = bone._d, r, cos, sin;
if (tangents)
r = positions[p - 1];
else if (_spaces[i + 1] < PathConstraint::EPSILON)
r = positions[p + 2];
else
r = MathUtil::atan2(dy, dx);
r -= MathUtil::atan2(c, a);
if (tip) {
cos = MathUtil::cos(r);
sin = MathUtil::sin(r);
float length = bone._data.getLength();
boneX += (length * (cos * a - sin * c) - dx) * rotateMix;
boneY += (length * (sin * a + cos * c) - dy) * rotateMix;
} else
r += offsetRotation;
if (r > MathUtil::Pi)
r -= MathUtil::Pi_2;
else if (r < -MathUtil::Pi)
r += MathUtil::Pi_2;
r *= rotateMix;
cos = MathUtil::cos(r);
sin = MathUtil::sin(r);
bone._a = cos * a - sin * c;
bone._b = cos * b - sin * d;
bone._c = sin * a + cos * c;
bone._d = sin * b + cos * d;
}
bone._appliedValid = false;
}
}
int PathConstraint::getOrder() {
return _data.getOrder();
}
float PathConstraint::getPosition() {
return _position;
}
void PathConstraint::setPosition(float inValue) {
_position = inValue;
}
float PathConstraint::getSpacing() {
return _spacing;
}
void PathConstraint::setSpacing(float inValue) {
_spacing = inValue;
}
float PathConstraint::getRotateMix() {
return _rotateMix;
}
void PathConstraint::setRotateMix(float inValue) {
_rotateMix = inValue;
}
float PathConstraint::getTranslateMix() {
return _translateMix;
}
void PathConstraint::setTranslateMix(float inValue) {
_translateMix = inValue;
}
Vector<Bone *> &PathConstraint::getBones() {
return _bones;
}
Slot *PathConstraint::getTarget() {
return _target;
}
void PathConstraint::setTarget(Slot *inValue) {
_target = inValue;
}
PathConstraintData &PathConstraint::getData() {
return _data;
}
Vector<float> &
PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing) {
Slot &target = *_target;
float position = _position;
_positions.setSize(spacesCount * 3 + 2, 0);
Vector<float> &out = _positions;
Vector<float> &world = _world;
bool closed = path.isClosed();
int verticesLength = path.getWorldVerticesLength();
int curveCount = verticesLength / 6;
int prevCurve = NONE;
float pathLength;
if (!path.isConstantSpeed()) {
Vector<float> &lengths = path.getLengths();
curveCount -= closed ? 1 : 2;
pathLength = lengths[curveCount];
if (percentPosition) position *= pathLength;
if (percentSpacing) {
for (int i = 1; i < spacesCount; ++i)
_spaces[i] *= pathLength;
}
world.setSize(8, 0);
for (int i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
float space = _spaces[i];
position += space;
float p = position;
if (closed) {
p = MathUtil::fmod(p, pathLength);
if (p < 0) p += pathLength;
curve = 0;
} else if (p < 0) {
if (prevCurve != BEFORE) {
prevCurve = BEFORE;
path.computeWorldVertices(target, 2, 4, world, 0);
}
addBeforePosition(p, world, 0, out, o);
continue;
} else if (p > pathLength) {
if (prevCurve != AFTER) {
prevCurve = AFTER;
path.computeWorldVertices(target, verticesLength - 6, 4, world, 0);
}
addAfterPosition(p - pathLength, world, 0, out, o);
continue;
}
// Determine curve containing position.
for (;; curve++) {
float length = lengths[curve];
if (p > length) continue;
if (curve == 0)
p /= length;
else {
float prev = lengths[curve - 1];
p = (p - prev) / (length - prev);
}
break;
}
if (curve != prevCurve) {
prevCurve = curve;
if (closed && curve == curveCount) {
path.computeWorldVertices(target, verticesLength - 4, 4, world, 0);
path.computeWorldVertices(target, 0, 4, world, 4);
} else
path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0);
}
addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7],
out, o, tangents || (i > 0 && space < EPSILON));
}
return out;
}
// World vertices.
if (closed) {
verticesLength += 2;
world.setSize(verticesLength, 0);
path.computeWorldVertices(target, 2, verticesLength - 4, world, 0);
path.computeWorldVertices(target, 0, 2, world, verticesLength - 4);
world[verticesLength - 2] = world[0];
world[verticesLength - 1] = world[1];
} else {
curveCount--;
verticesLength -= 4;
world.setSize(verticesLength, 0);
path.computeWorldVertices(target, 2, verticesLength, world, 0);
}
// Curve lengths.
_curves.setSize(curveCount, 0);
pathLength = 0;
float x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
float tmpx, tmpy, dddfx, dddfy, ddfx, ddfy, dfx, dfy;
for (int i = 0, w = 2; i < curveCount; i++, w += 6) {
cx1 = world[w];
cy1 = world[w + 1];
cx2 = world[w + 2];
cy2 = world[w + 3];
x2 = world[w + 4];
y2 = world[w + 5];
tmpx = (x1 - cx1 * 2 + cx2) * 0.1875f;
tmpy = (y1 - cy1 * 2 + cy2) * 0.1875f;
dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375f;
dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375f;
ddfx = tmpx * 2 + dddfx;
ddfy = tmpy * 2 + dddfy;
dfx = (cx1 - x1) * 0.75f + tmpx + dddfx * 0.16666667f;
dfy = (cy1 - y1) * 0.75f + tmpy + dddfy * 0.16666667f;
pathLength += MathUtil::sqrt(dfx * dfx + dfy * dfy);
dfx += ddfx;
dfy += ddfy;
ddfx += dddfx;
ddfy += dddfy;
pathLength += MathUtil::sqrt(dfx * dfx + dfy * dfy);
dfx += ddfx;
dfy += ddfy;
pathLength += MathUtil::sqrt(dfx * dfx + dfy * dfy);
dfx += ddfx + dddfx;
dfy += ddfy + dddfy;
pathLength += MathUtil::sqrt(dfx * dfx + dfy * dfy);
_curves[i] = pathLength;
x1 = x2;
y1 = y2;
}
if (percentPosition)
position *= pathLength;
else
position *= pathLength / path.getLengths()[curveCount - 1];
if (percentSpacing) {
for (int i = 1; i < spacesCount; ++i)
_spaces[i] *= pathLength;
}
float curveLength = 0;
for (int i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
float space = _spaces[i];
position += space;
float p = position;
if (closed) {
p = MathUtil::fmod(p, pathLength);
if (p < 0) p += pathLength;
curve = 0;
} else if (p < 0) {
addBeforePosition(p, world, 0, out, o);
continue;
} else if (p > pathLength) {
addAfterPosition(p - pathLength, world, verticesLength - 4, out, o);
continue;
}
// Determine curve containing position.
for (;; curve++) {
float length = _curves[curve];
if (p > length) continue;
if (curve == 0)
p /= length;
else {
float prev = _curves[curve - 1];
p = (p - prev) / (length - prev);
}
break;
}
// Curve segment lengths.
if (curve != prevCurve) {
prevCurve = curve;
int ii = curve * 6;
x1 = world[ii];
y1 = world[ii + 1];
cx1 = world[ii + 2];
cy1 = world[ii + 3];
cx2 = world[ii + 4];
cy2 = world[ii + 5];
x2 = world[ii + 6];
y2 = world[ii + 7];
tmpx = (x1 - cx1 * 2 + cx2) * 0.03f;
tmpy = (y1 - cy1 * 2 + cy2) * 0.03f;
dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006f;
dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006f;
ddfx = tmpx * 2 + dddfx;
ddfy = tmpy * 2 + dddfy;
dfx = (cx1 - x1) * 0.3f + tmpx + dddfx * 0.16666667f;
dfy = (cy1 - y1) * 0.3f + tmpy + dddfy * 0.16666667f;
curveLength = MathUtil::sqrt(dfx * dfx + dfy * dfy);
_segments[0] = curveLength;
for (ii = 1; ii < 8; ii++) {
dfx += ddfx;
dfy += ddfy;
ddfx += dddfx;
ddfy += dddfy;
curveLength += MathUtil::sqrt(dfx * dfx + dfy * dfy);
_segments[ii] = curveLength;
}
dfx += ddfx;
dfy += ddfy;
curveLength += MathUtil::sqrt(dfx * dfx + dfy * dfy);
_segments[8] = curveLength;
dfx += ddfx + dddfx;
dfy += ddfy + dddfy;
curveLength += MathUtil::sqrt(dfx * dfx + dfy * dfy);
_segments[9] = curveLength;
segment = 0;
}
// Weight by segment length.
p *= curveLength;
for (;; segment++) {
float length = _segments[segment];
if (p > length) continue;
if (segment == 0)
p /= length;
else {
float prev = _segments[segment - 1];
p = segment + (p - prev) / (length - prev);
}
break;
}
addCurvePosition(p * 0.1f, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o,
tangents || (i > 0 && space < EPSILON));
}
return out;
}
void PathConstraint::addBeforePosition(float p, Vector<float> &temp, int i, Vector<float> &output, int o) {
float x1 = temp[i];
float y1 = temp[i + 1];
float dx = temp[i + 2] - x1;
float dy = temp[i + 3] - y1;
float r = MathUtil::atan2(dy, dx);
output[o] = x1 + p * MathUtil::cos(r);
output[o + 1] = y1 + p * MathUtil::sin(r);
output[o + 2] = r;
}
void PathConstraint::addAfterPosition(float p, Vector<float> &temp, int i, Vector<float> &output, int o) {
float x1 = temp[i + 2];
float y1 = temp[i + 3];
float dx = x1 - temp[i];
float dy = y1 - temp[i + 1];
float r = MathUtil::atan2(dy, dx);
output[o] = x1 + p * MathUtil::cos(r);
output[o + 1] = y1 + p * MathUtil::sin(r);
output[o + 2] = r;
}
void PathConstraint::addCurvePosition(float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2,
float y2, Vector<float> &output, int o, bool tangents) {
if (p < EPSILON || MathUtil::isNan(p)) {
output[o] = x1;
output[o + 1] = y1;
output[o + 2] = MathUtil::atan2(cy1 - y1, cx1 - x1);
return;
}
float tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
float ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p;
float x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
output[o] = x;
output[o + 1] = y;
if (tangents) {
if (p < 0.001)
output[o + 2] = MathUtil::atan2(cy1 - y1, cx1 - x1);
else
output[o + 2] = MathUtil::atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
}
}
bool PathConstraint::isActive() {
return _active;
}
void PathConstraint::setActive(bool inValue) {
_active = inValue;
}

View File

@@ -0,0 +1,115 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_PathConstraint_h
#define Spine_PathConstraint_h
#include <spine/ConstraintData.h>
#include <spine/Vector.h>
namespace spine {
class PathConstraintData;
class Skeleton;
class PathAttachment;
class Bone;
class Slot;
class SP_API PathConstraint : public Updatable {
friend class Skeleton;
friend class PathConstraintMixTimeline;
friend class PathConstraintPositionTimeline;
friend class PathConstraintSpacingTimeline;
RTTI_DECL
public:
PathConstraint(PathConstraintData& data, Skeleton& skeleton);
/// Applies the constraint to the constrained bones.
void apply();
virtual void update();
virtual int getOrder();
float getPosition();
void setPosition(float inValue);
float getSpacing();
void setSpacing(float inValue);
float getRotateMix();
void setRotateMix(float inValue);
float getTranslateMix();
void setTranslateMix(float inValue);
Vector<Bone*>& getBones();
Slot* getTarget();
void setTarget(Slot* inValue);
PathConstraintData& getData();
bool isActive();
void setActive(bool inValue);
private:
static const float EPSILON;
static const int NONE;
static const int BEFORE;
static const int AFTER;
PathConstraintData& _data;
Vector<Bone*> _bones;
Slot* _target;
float _position, _spacing, _rotateMix, _translateMix;
Vector<float> _spaces;
Vector<float> _positions;
Vector<float> _world;
Vector<float> _curves;
Vector<float> _lengths;
Vector<float> _segments;
bool _active;
Vector<float>& computeWorldPositions(PathAttachment& path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing);
static void addBeforePosition(float p, Vector<float>& temp, int i, Vector<float>& output, int o);
static void addAfterPosition(float p, Vector<float>& temp, int i, Vector<float>& output, int o);
static void addCurvePosition(float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, Vector<float>& output, int o, bool tangents);
};
} // namespace spine
#endif /* Spine_PathConstraint_h */

View File

@@ -0,0 +1,129 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/PathConstraintData.h>
#include <spine/BoneData.h>
#include <spine/SlotData.h>
#include <assert.h>
using namespace spine;
PathConstraintData::PathConstraintData(const String &name) : ConstraintData(name),
_target(NULL),
_positionMode(PositionMode_Fixed),
_spacingMode(SpacingMode_Length),
_rotateMode(RotateMode_Tangent),
_offsetRotation(0),
_position(0),
_spacing(0),
_rotateMix(0),
_translateMix(0) {
}
Vector<BoneData *> &PathConstraintData::getBones() {
return _bones;
}
SlotData *PathConstraintData::getTarget() {
return _target;
}
void PathConstraintData::setTarget(SlotData *inValue) {
_target = inValue;
}
PositionMode PathConstraintData::getPositionMode() {
return _positionMode;
}
void PathConstraintData::setPositionMode(PositionMode inValue) {
_positionMode = inValue;
}
SpacingMode PathConstraintData::getSpacingMode() {
return _spacingMode;
}
void PathConstraintData::setSpacingMode(SpacingMode inValue) {
_spacingMode = inValue;
}
RotateMode PathConstraintData::getRotateMode() {
return _rotateMode;
}
void PathConstraintData::setRotateMode(RotateMode inValue) {
_rotateMode = inValue;
}
float PathConstraintData::getOffsetRotation() {
return _offsetRotation;
}
void PathConstraintData::setOffsetRotation(float inValue) {
_offsetRotation = inValue;
}
float PathConstraintData::getPosition() {
return _position;
}
void PathConstraintData::setPosition(float inValue) {
_position = inValue;
}
float PathConstraintData::getSpacing() {
return _spacing;
}
void PathConstraintData::setSpacing(float inValue) {
_spacing = inValue;
}
float PathConstraintData::getRotateMix() {
return _rotateMix;
}
void PathConstraintData::setRotateMix(float inValue) {
_rotateMix = inValue;
}
float PathConstraintData::getTranslateMix() {
return _translateMix;
}
void PathConstraintData::setTranslateMix(float inValue) {
_translateMix = inValue;
}

View File

@@ -0,0 +1,98 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_PathConstraintData_h
#define Spine_PathConstraintData_h
#include <spine/ConstraintData.h>
#include <spine/PositionMode.h>
#include <spine/RotateMode.h>
#include <spine/SpacingMode.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
#include <spine/Vector.h>
namespace spine {
class BoneData;
class SlotData;
class SP_API PathConstraintData : public ConstraintData {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class PathConstraint;
friend class Skeleton;
friend class PathConstraintMixTimeline;
friend class PathConstraintPositionTimeline;
friend class PathConstraintSpacingTimeline;
public:
explicit PathConstraintData(const String& name);
Vector<BoneData*>& getBones();
SlotData* getTarget();
void setTarget(SlotData* inValue);
PositionMode getPositionMode();
void setPositionMode(PositionMode inValue);
SpacingMode getSpacingMode();
void setSpacingMode(SpacingMode inValue);
RotateMode getRotateMode();
void setRotateMode(RotateMode inValue);
float getOffsetRotation();
void setOffsetRotation(float inValue);
float getPosition();
void setPosition(float inValue);
float getSpacing();
void setSpacing(float inValue);
float getRotateMix();
void setRotateMix(float inValue);
float getTranslateMix();
void setTranslateMix(float inValue);
private:
Vector<BoneData*> _bones;
SlotData* _target;
PositionMode _positionMode;
SpacingMode _spacingMode;
RotateMode _rotateMode;
float _offsetRotation;
float _position, _spacing, _rotateMix, _translateMix;
};
} // namespace spine
#endif /* Spine_PathConstraintData_h */

View File

@@ -0,0 +1,124 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/PathConstraintMixTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/PathConstraint.h>
#include <spine/PathConstraintData.h>
#include <spine/Slot.h>
#include <spine/SlotData.h>
#include <spine/TimelineType.h>
using namespace spine;
RTTI_IMPL(PathConstraintMixTimeline, CurveTimeline)
const int PathConstraintMixTimeline::ENTRIES = 3;
const int PathConstraintMixTimeline::PREV_TIME = -3;
const int PathConstraintMixTimeline::PREV_ROTATE = -2;
const int PathConstraintMixTimeline::PREV_TRANSLATE = -1;
const int PathConstraintMixTimeline::ROTATE = 1;
const int PathConstraintMixTimeline::TRANSLATE = 2;
PathConstraintMixTimeline::PathConstraintMixTimeline(int frameCount) : CurveTimeline(frameCount),
_pathConstraintIndex(0) {
_frames.setSize(frameCount * ENTRIES, 0);
}
void PathConstraintMixTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
SP_UNUSED(direction);
PathConstraint *constraintP = skeleton._pathConstraints[_pathConstraintIndex];
PathConstraint &constraint = *constraintP;
if (!constraint.isActive()) return;
if (time < _frames[0]) {
switch (blend) {
case MixBlend_Setup:
constraint._rotateMix = constraint._data._rotateMix;
constraint._translateMix = constraint._data._translateMix;
return;
case MixBlend_First:
constraint._rotateMix += (constraint._data._rotateMix - constraint._rotateMix) * alpha;
constraint._translateMix += (constraint._data._translateMix - constraint._translateMix) * alpha;
return;
default:
return;
}
}
float rotate, translate;
if (time >= _frames[_frames.size() - ENTRIES]) {
// Time is after last frame.
rotate = _frames[_frames.size() + PREV_ROTATE];
translate = _frames[_frames.size() + PREV_TRANSLATE];
} else {
// Interpolate between the previous frame and the current frame.
int frame = Animation::binarySearch(_frames, time, ENTRIES);
rotate = _frames[frame + PREV_ROTATE];
translate = _frames[frame + PREV_TRANSLATE];
float frameTime = _frames[frame];
float percent = getCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime));
rotate += (_frames[frame + ROTATE] - rotate) * percent;
translate += (_frames[frame + TRANSLATE] - translate) * percent;
}
if (blend == MixBlend_Setup) {
constraint._rotateMix = constraint._data._rotateMix + (rotate - constraint._data._rotateMix) * alpha;
constraint._translateMix =
constraint._data._translateMix + (translate - constraint._data._translateMix) * alpha;
} else {
constraint._rotateMix += (rotate - constraint._rotateMix) * alpha;
constraint._translateMix += (translate - constraint._translateMix) * alpha;
}
}
int PathConstraintMixTimeline::getPropertyId() {
return ((int)TimelineType_PathConstraintMix << 24) + _pathConstraintIndex;
}
void PathConstraintMixTimeline::setFrame(int frameIndex, float time, float rotateMix, float translateMix) {
frameIndex *= ENTRIES;
_frames[frameIndex] = time;
_frames[frameIndex + ROTATE] = rotateMix;
_frames[frameIndex + TRANSLATE] = translateMix;
}

View File

@@ -0,0 +1,68 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_PathConstraintMixTimeline_h
#define Spine_PathConstraintMixTimeline_h
#include <spine/CurveTimeline.h>
namespace spine {
#define SP_PATHCONSTRAINTMIXTIMELINE_ENTRIES 5
class SP_API PathConstraintMixTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
static const int ENTRIES;
explicit PathConstraintMixTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixBlend blend, MixDirection direction);
virtual int getPropertyId();
private:
static const int PREV_TIME;
static const int PREV_ROTATE;
static const int PREV_TRANSLATE;
static const int ROTATE;
static const int TRANSLATE;
Vector<float> _frames;
int _pathConstraintIndex;
/// Sets the time and mixes of the specified keyframe.
void setFrame(int frameIndex, float time, float rotateMix, float translateMix);
};
} // namespace spine
#endif /* Spine_PathConstraintMixTimeline_h */

View File

@@ -0,0 +1,114 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/PathConstraintPositionTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/PathConstraint.h>
#include <spine/PathConstraintData.h>
#include <spine/Slot.h>
#include <spine/SlotData.h>
#include <spine/TimelineType.h>
using namespace spine;
RTTI_IMPL(PathConstraintPositionTimeline, CurveTimeline)
const int PathConstraintPositionTimeline::ENTRIES = 2;
const int PathConstraintPositionTimeline::PREV_TIME = -2;
const int PathConstraintPositionTimeline::PREV_VALUE = -1;
const int PathConstraintPositionTimeline::VALUE = 1;
PathConstraintPositionTimeline::PathConstraintPositionTimeline(int frameCount) : CurveTimeline(frameCount),
_pathConstraintIndex(0) {
_frames.setSize(frameCount * ENTRIES, 0);
}
PathConstraintPositionTimeline::~PathConstraintPositionTimeline() {
}
void PathConstraintPositionTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents,
float alpha, MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
SP_UNUSED(direction);
PathConstraint *constraintP = skeleton._pathConstraints[_pathConstraintIndex];
PathConstraint &constraint = *constraintP;
if (!constraint.isActive()) return;
if (time < _frames[0]) {
switch (blend) {
case MixBlend_Setup:
constraint._position = constraint._data._position;
return;
case MixBlend_First:
constraint._position += (constraint._data._position - constraint._position) * alpha;
return;
default:
return;
}
}
float position;
if (time >= _frames[_frames.size() - ENTRIES]) {
// Time is after last frame.
position = _frames[_frames.size() + PREV_VALUE];
} else {
// Interpolate between the previous frame and the current frame.
int frame = Animation::binarySearch(_frames, time, ENTRIES);
position = _frames[frame + PREV_VALUE];
float frameTime = _frames[frame];
float percent = getCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime));
position += (_frames[frame + VALUE] - position) * percent;
}
if (blend == MixBlend_Setup)
constraint._position = constraint._data._position + (position - constraint._data._position) * alpha;
else
constraint._position += (position - constraint._position) * alpha;
}
int PathConstraintPositionTimeline::getPropertyId() {
return ((int)TimelineType_PathConstraintPosition << 24) + _pathConstraintIndex;
}
void PathConstraintPositionTimeline::setFrame(int frameIndex, float time, float value) {
frameIndex *= ENTRIES;
_frames[frameIndex] = time;
_frames[frameIndex + VALUE] = value;
}

View File

@@ -0,0 +1,67 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_PathConstraintPositionTimeline_h
#define Spine_PathConstraintPositionTimeline_h
#include <spine/CurveTimeline.h>
namespace spine {
class SP_API PathConstraintPositionTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
static const int ENTRIES;
explicit PathConstraintPositionTimeline(int frameCount);
virtual ~PathConstraintPositionTimeline();
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixBlend blend, MixDirection direction);
virtual int getPropertyId();
/// Sets the time and value of the specified keyframe.
void setFrame(int frameIndex, float time, float value);
protected:
static const int PREV_TIME;
static const int PREV_VALUE;
static const int VALUE;
Vector<float> _frames;
int _pathConstraintIndex;
};
} // namespace spine
#endif /* Spine_PathConstraintPositionTimeline_h */

View File

@@ -0,0 +1,100 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/PathConstraintSpacingTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/PathConstraint.h>
#include <spine/PathConstraintData.h>
#include <spine/Slot.h>
#include <spine/SlotData.h>
#include <spine/TimelineType.h>
using namespace spine;
RTTI_IMPL(PathConstraintSpacingTimeline, PathConstraintPositionTimeline)
PathConstraintSpacingTimeline::PathConstraintSpacingTimeline(int frameCount) : PathConstraintPositionTimeline(
frameCount) {
}
void PathConstraintSpacingTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents,
float alpha, MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
SP_UNUSED(direction);
PathConstraint *constraintP = skeleton._pathConstraints[_pathConstraintIndex];
PathConstraint &constraint = *constraintP;
if (!constraint.isActive()) return;
if (time < _frames[0]) {
switch (blend) {
case MixBlend_Setup:
constraint._spacing = constraint._data._spacing;
return;
case MixBlend_First:
constraint._spacing += (constraint._data._spacing - constraint._spacing) * alpha;
return;
default:
return;
}
}
float spacing;
if (time >= _frames[_frames.size() - ENTRIES]) {
// Time is after last frame.
spacing = _frames[_frames.size() + PREV_VALUE];
} else {
// Interpolate between the previous frame and the current frame.
int frame = Animation::binarySearch(_frames, time, ENTRIES);
spacing = _frames[frame + PREV_VALUE];
float frameTime = _frames[frame];
float percent = getCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime));
spacing += (_frames[frame + VALUE] - spacing) * percent;
}
if (blend == MixBlend_Setup)
constraint._spacing = constraint._data._spacing + (spacing - constraint._data._spacing) * alpha;
else
constraint._spacing += (spacing - constraint._spacing) * alpha;
}
int PathConstraintSpacingTimeline::getPropertyId() {
return ((int)TimelineType_PathConstraintSpacing << 24) + _pathConstraintIndex;
}

View File

@@ -0,0 +1,51 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_PathConstraintSpacingTimeline_h
#define Spine_PathConstraintSpacingTimeline_h
#include <spine/PathConstraintPositionTimeline.h>
namespace spine {
class SP_API PathConstraintSpacingTimeline : public PathConstraintPositionTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
explicit PathConstraintSpacingTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixBlend blend, MixDirection direction);
virtual int getPropertyId();
};
} // namespace spine
#endif /* Spine_PathConstraintSpacingTimeline_h */

View File

@@ -0,0 +1,90 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/PointAttachment.h>
#include <spine/Bone.h>
#include <spine/MathUtil.h>
using namespace spine;
RTTI_IMPL(PointAttachment, Attachment)
PointAttachment::PointAttachment(const String &name) : Attachment(name), _x(0), _y(0), _rotation(0) {
}
void PointAttachment::computeWorldPosition(Bone &bone, float &ox, float &oy) {
bone.localToWorld(_x, _y, ox, oy);
}
float PointAttachment::computeWorldRotation(Bone &bone) {
float cos = MathUtil::cosDeg(_rotation);
float sin = MathUtil::sinDeg(_rotation);
float ix = cos * bone._a + sin * bone._b;
float iy = cos * bone._c + sin * bone._d;
return MathUtil::atan2(iy, ix) * MathUtil::Rad_Deg;
}
float PointAttachment::getX() {
return _x;
}
void PointAttachment::setX(float inValue) {
_x = inValue;
}
float PointAttachment::getY() {
return _y;
}
void PointAttachment::setY(float inValue) {
_y = inValue;
}
float PointAttachment::getRotation() {
return _rotation;
}
void PointAttachment::setRotation(float inValue) {
_rotation = inValue;
}
Attachment *PointAttachment::copy() {
PointAttachment *copy = new (__FILE__, __LINE__) PointAttachment(getName());
copy->_x = _x;
copy->_y = _y;
copy->_rotation = _rotation;
return copy;
}

View File

@@ -0,0 +1,73 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_PointAttachment_h
#define Spine_PointAttachment_h
#include <spine/Attachment.h>
namespace spine {
class Bone;
/// An attachment which is a single point and a rotation. This can be used to spawn projectiles, particles, etc. A bone can be
/// used in similar ways, but a PointAttachment is slightly less expensive to compute and can be hidden, shown, and placed in a
/// skin.
///
/// See http://esotericsoftware.com/spine-point-attachments for Point Attachments in the Spine User Guide.
///
class SP_API PointAttachment : public Attachment {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
explicit PointAttachment(const String& name);
void computeWorldPosition(Bone& bone, float& ox, float& oy);
float computeWorldRotation(Bone& bone);
float getX();
void setX(float inValue);
float getY();
void setY(float inValue);
float getRotation();
void setRotation(float inValue);
virtual Attachment* copy();
private:
float _x, _y, _rotation;
};
} // namespace spine
#endif /* Spine_PointAttachment_h */

View File

@@ -0,0 +1,74 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_Pool_h
#define Spine_Pool_h
#include <spine/ContainerUtil.h>
#include <spine/Extension.h>
#include <spine/SpineObject.h>
#include <spine/Vector.h>
namespace spine {
template <typename T>
class SP_API Pool : public SpineObject {
public:
Pool() {
}
~Pool() {
ContainerUtil::cleanUpVectorOfPointers(_objects);
}
T *obtain() {
if (_objects.size() > 0) {
T **object = &_objects[_objects.size() - 1];
T *ret = *object;
_objects.removeAt(_objects.size() - 1);
return ret;
} else {
T *ret = new (__FILE__, __LINE__) T();
return ret;
}
}
void free(T *object) {
if (!_objects.contains(object)) {
_objects.add(object);
}
}
private:
Vector<T *> _objects;
};
} // namespace spine
#endif /* Spine_Pool_h */

View File

@@ -0,0 +1,40 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_PositionMode_h
#define Spine_PositionMode_h
namespace spine {
enum PositionMode {
PositionMode_Fixed = 0,
PositionMode_Percent
};
}
#endif /* Spine_PositionMode_h */

View File

@@ -0,0 +1,60 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/RTTI.h>
#include <spine/SpineString.h>
using namespace spine;
RTTI::RTTI(const char *className) : _className(className), _pBaseRTTI(NULL) {
}
RTTI::RTTI(const char *className, const RTTI &baseRTTI) : _className(className), _pBaseRTTI(&baseRTTI) {
}
const char *RTTI::getClassName() const {
return _className;
}
bool RTTI::isExactly(const RTTI &rtti) const {
return !strcmp(this->_className, rtti._className);
}
bool RTTI::instanceOf(const RTTI &rtti) const {
const RTTI *pCompare = this;
while (pCompare) {
if (!strcmp(pCompare->_className, rtti._className)) return true;
pCompare = pCompare->_pBaseRTTI;
}
return false;
}

View File

@@ -0,0 +1,72 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_RTTI_h
#define Spine_RTTI_h
#include <spine/SpineObject.h>
namespace spine {
class SP_API RTTI : public SpineObject {
public:
explicit RTTI(const char *className);
RTTI(const char *className, const RTTI &baseRTTI);
const char *getClassName() const;
bool isExactly(const RTTI &rtti) const;
bool instanceOf(const RTTI &rtti) const;
private:
// Prevent copying
RTTI(const RTTI &obj);
RTTI &operator=(const RTTI &obj);
const char *_className;
const RTTI *_pBaseRTTI;
};
} // namespace spine
#define RTTI_DECL \
public: \
static const spine::RTTI rtti; \
virtual const spine::RTTI &getRTTI() const;
#define RTTI_IMPL_NOPARENT(name) \
const spine::RTTI name::rtti(#name); \
const spine::RTTI &name::getRTTI() const { return rtti; }
#define RTTI_IMPL(name, parent) \
const spine::RTTI name::rtti(#name, parent::rtti); \
const spine::RTTI &name::getRTTI() const { return rtti; }
#endif /* Spine_RTTI_h */

View File

@@ -0,0 +1,287 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/RegionAttachment.h>
#include <spine/Bone.h>
#include <assert.h>
using namespace spine;
RTTI_IMPL(RegionAttachment, Attachment)
const int RegionAttachment::BLX = 0;
const int RegionAttachment::BLY = 1;
const int RegionAttachment::ULX = 2;
const int RegionAttachment::ULY = 3;
const int RegionAttachment::URX = 4;
const int RegionAttachment::URY = 5;
const int RegionAttachment::BRX = 6;
const int RegionAttachment::BRY = 7;
RegionAttachment::RegionAttachment(const String &name) : Attachment(name), HasRendererObject(), _x(0), _y(0), _rotation(0), _scaleX(1), _scaleY(1), _width(0), _height(0), _regionOffsetX(0), _regionOffsetY(0), _regionWidth(0), _regionHeight(0), _regionOriginalWidth(0), _regionOriginalHeight(0), _path(), _regionU(0), _regionV(0), _regionU2(0), _regionV2(0), _color(1, 1, 1, 1) {
_vertexOffset.setSize(NUM_UVS, 0);
_uvs.setSize(NUM_UVS, 0);
}
void RegionAttachment::updateOffset() {
float regionScaleX = _width / _regionOriginalWidth * _scaleX;
float regionScaleY = _height / _regionOriginalHeight * _scaleY;
float localX = -_width / 2 * _scaleX + _regionOffsetX * regionScaleX;
float localY = -_height / 2 * _scaleY + _regionOffsetY * regionScaleY;
float localX2 = localX + _regionWidth * regionScaleX;
float localY2 = localY + _regionHeight * regionScaleY;
float cos = MathUtil::cosDeg(_rotation);
float sin = MathUtil::sinDeg(_rotation);
float localXCos = localX * cos + _x;
float localXSin = localX * sin;
float localYCos = localY * cos + _y;
float localYSin = localY * sin;
float localX2Cos = localX2 * cos + _x;
float localX2Sin = localX2 * sin;
float localY2Cos = localY2 * cos + _y;
float localY2Sin = localY2 * sin;
_vertexOffset[BLX] = localXCos - localYSin;
_vertexOffset[BLY] = localYCos + localXSin;
_vertexOffset[ULX] = localXCos - localY2Sin;
_vertexOffset[ULY] = localY2Cos + localXSin;
_vertexOffset[URX] = localX2Cos - localY2Sin;
_vertexOffset[URY] = localY2Cos + localX2Sin;
_vertexOffset[BRX] = localX2Cos - localYSin;
_vertexOffset[BRY] = localYCos + localX2Sin;
}
void RegionAttachment::setUVs(float u, float v, float u2, float v2, bool rotate) {
if (rotate) {
_uvs[URX] = u;
_uvs[URY] = v2;
_uvs[BRX] = u;
_uvs[BRY] = v;
_uvs[BLX] = u2;
_uvs[BLY] = v;
_uvs[ULX] = u2;
_uvs[ULY] = v2;
} else {
_uvs[ULX] = u;
_uvs[ULY] = v2;
_uvs[URX] = u;
_uvs[URY] = v;
_uvs[BRX] = u2;
_uvs[BRY] = v;
_uvs[BLX] = u2;
_uvs[BLY] = v2;
}
}
void RegionAttachment::computeWorldVertices(Bone &bone, Vector<float> &worldVertices, size_t offset, size_t stride) {
assert(worldVertices.size() >= (offset + 8));
computeWorldVertices(bone, worldVertices.buffer(), offset, stride);
}
void RegionAttachment::computeWorldVertices(Bone &bone, float *worldVertices, size_t offset, size_t stride) {
float x = bone.getWorldX(), y = bone.getWorldY();
float a = bone.getA(), b = bone.getB(), c = bone.getC(), d = bone.getD();
float offsetX, offsetY;
offsetX = _vertexOffset[BRX];
offsetY = _vertexOffset[BRY];
worldVertices[offset] = offsetX * a + offsetY * b + x; // br
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
offset += stride;
offsetX = _vertexOffset[BLX];
offsetY = _vertexOffset[BLY];
worldVertices[offset] = offsetX * a + offsetY * b + x; // bl
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
offset += stride;
offsetX = _vertexOffset[ULX];
offsetY = _vertexOffset[ULY];
worldVertices[offset] = offsetX * a + offsetY * b + x; // ul
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
offset += stride;
offsetX = _vertexOffset[URX];
offsetY = _vertexOffset[URY];
worldVertices[offset] = offsetX * a + offsetY * b + x; // ur
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
}
float RegionAttachment::getX() {
return _x;
}
void RegionAttachment::setX(float inValue) {
_x = inValue;
}
float RegionAttachment::getY() {
return _y;
}
void RegionAttachment::setY(float inValue) {
_y = inValue;
}
float RegionAttachment::getRotation() {
return _rotation;
}
void RegionAttachment::setRotation(float inValue) {
_rotation = inValue;
}
float RegionAttachment::getScaleX() {
return _scaleX;
}
void RegionAttachment::setScaleX(float inValue) {
_scaleX = inValue;
}
float RegionAttachment::getScaleY() {
return _scaleY;
}
void RegionAttachment::setScaleY(float inValue) {
_scaleY = inValue;
}
float RegionAttachment::getWidth() {
return _width;
}
void RegionAttachment::setWidth(float inValue) {
_width = inValue;
}
float RegionAttachment::getHeight() {
return _height;
}
void RegionAttachment::setHeight(float inValue) {
_height = inValue;
}
const String &RegionAttachment::getPath() {
return _path;
}
void RegionAttachment::setPath(const String &inValue) {
_path = inValue;
}
float RegionAttachment::getRegionOffsetX() {
return _regionOffsetX;
}
void RegionAttachment::setRegionOffsetX(float inValue) {
_regionOffsetX = inValue;
}
float RegionAttachment::getRegionOffsetY() {
return _regionOffsetY;
}
void RegionAttachment::setRegionOffsetY(float inValue) {
_regionOffsetY = inValue;
}
float RegionAttachment::getRegionWidth() {
return _regionWidth;
}
void RegionAttachment::setRegionWidth(float inValue) {
_regionWidth = inValue;
}
float RegionAttachment::getRegionHeight() {
return _regionHeight;
}
void RegionAttachment::setRegionHeight(float inValue) {
_regionHeight = inValue;
}
float RegionAttachment::getRegionOriginalWidth() {
return _regionOriginalWidth;
}
void RegionAttachment::setRegionOriginalWidth(float inValue) {
_regionOriginalWidth = inValue;
}
float RegionAttachment::getRegionOriginalHeight() {
return _regionOriginalHeight;
}
void RegionAttachment::setRegionOriginalHeight(float inValue) {
_regionOriginalHeight = inValue;
}
Vector<float> &RegionAttachment::getOffset() {
return _vertexOffset;
}
Vector<float> &RegionAttachment::getUVs() {
return _uvs;
}
spine::Color &RegionAttachment::getColor() {
return _color;
}
Attachment *RegionAttachment::copy() {
RegionAttachment *copy = new (__FILE__, __LINE__) RegionAttachment(getName());
copy->_regionWidth = _regionWidth;
copy->_regionHeight = _regionHeight;
copy->_regionOffsetX = _regionOffsetX;
copy->_regionOffsetY = _regionOffsetY;
copy->_regionOriginalWidth = _regionOriginalWidth;
copy->_regionOriginalHeight = _regionOriginalHeight;
copy->setRendererObject(getRendererObject());
copy->_path = _path;
copy->_x = _x;
copy->_y = _y;
copy->_scaleX = _scaleX;
copy->_scaleY = _scaleY;
copy->_rotation = _rotation;
copy->_width = _width;
copy->_height = _height;
copy->_uvs.clearAndAddAll(_uvs);
copy->_vertexOffset.clearAndAddAll(_vertexOffset);
copy->_color.set(_color);
return copy;
}

View File

@@ -0,0 +1,133 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_RegionAttachment_h
#define Spine_RegionAttachment_h
#include <spine/Attachment.h>
#include <spine/Color.h>
#include <spine/Vector.h>
#include <spine/HasRendererObject.h>
#define NUM_UVS 8
namespace spine {
class Bone;
/// Attachment that displays a texture region.
class SP_API RegionAttachment : public Attachment, public HasRendererObject {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class AtlasAttachmentLoader;
RTTI_DECL
public:
explicit RegionAttachment(const String& name);
void updateOffset();
void setUVs(float u, float v, float u2, float v2, bool rotate);
/// Transforms the attachment's four vertices to world coordinates.
/// @param bone The parent bone.
/// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + 8.
/// @param offset The worldVertices index to begin writing values.
/// @param stride The number of worldVertices entries between the value pairs written.
void computeWorldVertices(Bone& bone, float* worldVertices, size_t offset, size_t stride = 2);
void computeWorldVertices(Bone& bone, Vector<float>& worldVertices, size_t offset, size_t stride = 2);
float getX();
void setX(float inValue);
float getY();
void setY(float inValue);
float getRotation();
void setRotation(float inValue);
float getScaleX();
void setScaleX(float inValue);
float getScaleY();
void setScaleY(float inValue);
float getWidth();
void setWidth(float inValue);
float getHeight();
void setHeight(float inValue);
Color& getColor();
const String& getPath();
void setPath(const String& inValue);
float getRegionOffsetX();
void setRegionOffsetX(float inValue);
float getRegionOffsetY();
void setRegionOffsetY(float inValue);
float getRegionWidth();
void setRegionWidth(float inValue);
float getRegionHeight();
void setRegionHeight(float inValue);
float getRegionOriginalWidth();
void setRegionOriginalWidth(float inValue);
float getRegionOriginalHeight();
void setRegionOriginalHeight(float inValue);
Vector<float>& getOffset();
Vector<float>& getUVs();
virtual Attachment* copy();
private:
static const int BLX;
static const int BLY;
static const int ULX;
static const int ULY;
static const int URX;
static const int URY;
static const int BRX;
static const int BRY;
float _x, _y, _rotation, _scaleX, _scaleY, _width, _height;
float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight;
Vector<float> _vertexOffset;
Vector<float> _uvs;
String _path;
float _regionU;
float _regionV;
float _regionU2;
float _regionV2;
Color _color;
};
} // namespace spine
#endif /* Spine_RegionAttachment_h */

View File

@@ -0,0 +1,41 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_RotateMode_h
#define Spine_RotateMode_h
namespace spine {
enum RotateMode {
RotateMode_Tangent = 0,
RotateMode_Chain,
RotateMode_ChainScale
};
}
#endif /* Spine_RotateMode_h */

View File

@@ -0,0 +1,138 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/RotateTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/Bone.h>
#include <spine/BoneData.h>
#include <spine/TimelineType.h>
using namespace spine;
RTTI_IMPL(RotateTimeline, CurveTimeline)
RotateTimeline::RotateTimeline(int frameCount) : CurveTimeline(frameCount), _boneIndex(0) {
_frames.setSize(frameCount << 1, 0);
}
void RotateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
SP_UNUSED(direction);
Bone *bone = skeleton.getBones()[_boneIndex];
if (!bone->_active) return;
if (time < _frames[0]) {
switch (blend) {
case MixBlend_Setup: {
bone->_rotation = bone->_data._rotation;
break;
}
case MixBlend_First: {
float r = bone->_data._rotation - bone->_rotation;
bone->_rotation += (r - (16384 - (int)(16384.499999999996 - r / 360)) * 360) * alpha;
break;
}
default: {
// TODO?
break;
}
}
return;
}
if (time >= _frames[_frames.size() - ENTRIES]) {
float r = _frames[_frames.size() + PREV_ROTATION];
switch (blend) {
case MixBlend_Setup:
bone->_rotation = bone->_data._rotation + r * alpha;
break;
case MixBlend_First:
case MixBlend_Replace:
r += bone->_data._rotation - bone->_rotation;
r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360;
// Fall through.
case MixBlend_Add:
bone->_rotation += r * alpha;
}
return;
}
// Interpolate between the previous frame and the current frame.
int frame = Animation::binarySearch(_frames, time, ENTRIES);
float prevRotation = _frames[frame + PREV_ROTATION];
float frameTime = _frames[frame];
float percent = getCurvePercent((frame >> 1) - 1,
1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime));
float r = _frames[frame + ROTATION] - prevRotation;
r = prevRotation + (r - (16384 - (int)(16384.499999999996 - r / 360)) * 360) * percent;
switch (blend) {
case MixBlend_Setup:
bone->_rotation = bone->_data._rotation + (r - (16384 - (int)(16384.499999999996 - r / 360)) * 360) * alpha;
break;
case MixBlend_First:
case MixBlend_Replace:
r += bone->_data._rotation - bone->_rotation;
// Fall through.
case MixBlend_Add:
bone->_rotation += (r - (16384 - (int)(16384.499999999996 - r / 360)) * 360) * alpha;
}
}
int RotateTimeline::getPropertyId() {
return ((int)TimelineType_Rotate << 24) + _boneIndex;
}
void RotateTimeline::setFrame(int frameIndex, float time, float degrees) {
frameIndex <<= 1;
_frames[frameIndex] = time;
_frames[frameIndex + ROTATION] = degrees;
}
int RotateTimeline::getBoneIndex() {
return _boneIndex;
}
void RotateTimeline::setBoneIndex(int inValue) {
_boneIndex = inValue;
}
Vector<float> &RotateTimeline::getFrames() {
return _frames;
}

View File

@@ -0,0 +1,70 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_RotateTimeline_h
#define Spine_RotateTimeline_h
#include <spine/CurveTimeline.h>
namespace spine {
class SP_API RotateTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class AnimationState;
RTTI_DECL
public:
static const int ENTRIES = 2;
explicit RotateTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixBlend blend, MixDirection direction);
virtual int getPropertyId();
/// Sets the time and value of the specified keyframe.
void setFrame(int frameIndex, float time, float degrees);
int getBoneIndex();
void setBoneIndex(int inValue);
Vector<float>& getFrames();
private:
static const int PREV_TIME = -2;
static const int PREV_ROTATION = -1;
static const int ROTATION = 1;
int _boneIndex;
Vector<float> _frames; // time, angle, ...
};
} // namespace spine
#endif /* Spine_RotateTimeline_h */

View File

@@ -0,0 +1,153 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/ScaleTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Bone.h>
#include <spine/BoneData.h>
#include <spine/Slot.h>
#include <spine/SlotData.h>
using namespace spine;
RTTI_IMPL(ScaleTimeline, TranslateTimeline)
ScaleTimeline::ScaleTimeline(int frameCount) : TranslateTimeline(frameCount) {
}
void ScaleTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
Bone *boneP = skeleton._bones[_boneIndex];
Bone &bone = *boneP;
if (!bone._active) return;
if (time < _frames[0]) {
switch (blend) {
case MixBlend_Setup:
bone._scaleX = bone._data._scaleX;
bone._scaleY = bone._data._scaleY;
return;
case MixBlend_First:
bone._scaleX += (bone._data._scaleX - bone._scaleX) * alpha;
bone._scaleY += (bone._data._scaleY - bone._scaleY) * alpha;
default: {
}
}
return;
}
float x, y;
if (time >= _frames[_frames.size() - ENTRIES]) {
// Time is after last frame.
x = _frames[_frames.size() + PREV_X] * bone._data._scaleX;
y = _frames[_frames.size() + PREV_Y] * bone._data._scaleY;
} else {
// Interpolate between the previous frame and the current frame.
int frame = Animation::binarySearch(_frames, time, ENTRIES);
x = _frames[frame + PREV_X];
y = _frames[frame + PREV_Y];
float frameTime = _frames[frame];
float percent = getCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime));
x = (x + (_frames[frame + X] - x) * percent) * bone._data._scaleX;
y = (y + (_frames[frame + Y] - y) * percent) * bone._data._scaleY;
}
if (alpha == 1) {
if (blend == MixBlend_Add) {
bone._scaleX += x - bone._data._scaleX;
bone._scaleY += y - bone._data._scaleY;
} else {
bone._scaleX = x;
bone._scaleY = y;
}
} else {
// Mixing out uses sign of setup or current pose, else use sign of key.
float bx, by;
if (direction == MixDirection_Out) {
switch (blend) {
case MixBlend_Setup:
bx = bone._data._scaleX;
by = bone._data._scaleY;
bone._scaleX = bx + (MathUtil::abs(x) * MathUtil::sign(bx) - bx) * alpha;
bone._scaleY = by + (MathUtil::abs(y) * MathUtil::sign(by) - by) * alpha;
break;
case MixBlend_First:
case MixBlend_Replace:
bx = bone._scaleX;
by = bone._scaleY;
bone._scaleX = bx + (MathUtil::abs(x) * MathUtil::sign(bx) - bx) * alpha;
bone._scaleY = by + (MathUtil::abs(y) * MathUtil::sign(by) - by) * alpha;
break;
case MixBlend_Add:
bx = bone._scaleX;
by = bone._scaleY;
bone._scaleX = bx + (MathUtil::abs(x) * MathUtil::sign(bx) - bone._data._scaleX) * alpha;
bone._scaleY = by + (MathUtil::abs(y) * MathUtil::sign(by) - bone._data._scaleY) * alpha;
}
} else {
switch (blend) {
case MixBlend_Setup:
bx = MathUtil::abs(bone._data._scaleX) * MathUtil::sign(x);
by = MathUtil::abs(bone._data._scaleY) * MathUtil::sign(y);
bone._scaleX = bx + (x - bx) * alpha;
bone._scaleY = by + (y - by) * alpha;
break;
case MixBlend_First:
case MixBlend_Replace:
bx = MathUtil::abs(bone._scaleX) * MathUtil::sign(x);
by = MathUtil::abs(bone._scaleY) * MathUtil::sign(y);
bone._scaleX = bx + (x - bx) * alpha;
bone._scaleY = by + (y - by) * alpha;
break;
case MixBlend_Add:
bx = MathUtil::sign(x);
by = MathUtil::sign(y);
bone._scaleX = MathUtil::abs(bone._scaleX) * bx + (x - MathUtil::abs(bone._data._scaleX) * bx) * alpha;
bone._scaleY = MathUtil::abs(bone._scaleY) * by + (y - MathUtil::abs(bone._data._scaleY) * by) * alpha;
}
}
}
}
int ScaleTimeline::getPropertyId() {
return ((int)TimelineType_Scale << 24) + _boneIndex;
}

View File

@@ -0,0 +1,51 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_ScaleTimeline_h
#define Spine_ScaleTimeline_h
#include <spine/TranslateTimeline.h>
namespace spine {
class SP_API ScaleTimeline : public TranslateTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
explicit ScaleTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixBlend blend, MixDirection direction);
virtual int getPropertyId();
};
} // namespace spine
#endif /* Spine_ScaleTimeline_h */

View File

@@ -0,0 +1,112 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/ShearTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Bone.h>
#include <spine/BoneData.h>
#include <spine/Slot.h>
#include <spine/SlotData.h>
using namespace spine;
RTTI_IMPL(ShearTimeline, TranslateTimeline)
ShearTimeline::ShearTimeline(int frameCount) : TranslateTimeline(frameCount) {
}
void ShearTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
SP_UNUSED(direction);
Bone *boneP = skeleton._bones[_boneIndex];
Bone &bone = *boneP;
if (!bone._active) return;
if (time < _frames[0]) {
switch (blend) {
case MixBlend_Setup:
bone._shearX = bone._data._shearX;
bone._shearY = bone._data._shearY;
return;
case MixBlend_First:
bone._shearX += (bone._data._shearX - bone._shearX) * alpha;
bone._shearY += (bone._data._shearY - bone._shearY) * alpha;
default: {
}
}
return;
}
float x, y;
if (time >= _frames[_frames.size() - ENTRIES]) {
// Time is after last frame.
x = _frames[_frames.size() + PREV_X];
y = _frames[_frames.size() + PREV_Y];
} else {
// Interpolate between the previous frame and the current frame.
int frame = Animation::binarySearch(_frames, time, ENTRIES);
x = _frames[frame + PREV_X];
y = _frames[frame + PREV_Y];
float frameTime = _frames[frame];
float percent = getCurvePercent(frame / ENTRIES - 1,
1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime));
x = x + (_frames[frame + X] - x) * percent;
y = y + (_frames[frame + Y] - y) * percent;
}
switch (blend) {
case MixBlend_Setup:
bone._shearX = bone._data._shearX + x * alpha;
bone._shearY = bone._data._shearY + y * alpha;
break;
case MixBlend_First:
case MixBlend_Replace:
bone._shearX += (bone._data._shearX + x - bone._shearX) * alpha;
bone._shearY += (bone._data._shearY + y - bone._shearY) * alpha;
break;
case MixBlend_Add:
bone._shearX += x * alpha;
bone._shearY += y * alpha;
}
}
int ShearTimeline::getPropertyId() {
return ((int)TimelineType_Shear << 24) + _boneIndex;
}

View File

@@ -0,0 +1,51 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_ShearTimeline_h
#define Spine_ShearTimeline_h
#include <spine/TranslateTimeline.h>
namespace spine {
class SP_API ShearTimeline : public TranslateTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL
public:
explicit ShearTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixBlend blend, MixDirection direction);
virtual int getPropertyId();
};
} // namespace spine
#endif /* Spine_ShearTimeline_h */

View File

@@ -0,0 +1,681 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/Skeleton.h>
#include <spine/Attachment.h>
#include <spine/Bone.h>
#include <spine/IkConstraint.h>
#include <spine/PathConstraint.h>
#include <spine/SkeletonData.h>
#include <spine/Skin.h>
#include <spine/Slot.h>
#include <spine/TransformConstraint.h>
#include <spine/BoneData.h>
#include <spine/IkConstraintData.h>
#include <spine/MeshAttachment.h>
#include <spine/PathAttachment.h>
#include <spine/PathConstraintData.h>
#include <spine/RegionAttachment.h>
#include <spine/SlotData.h>
#include <spine/TransformConstraintData.h>
#include <spine/ContainerUtil.h>
#include <float.h>
using namespace spine;
Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData),
_skin(NULL),
_color(1, 1, 1, 1),
_time(0),
_scaleX(1),
_scaleY(1),
_x(0),
_y(0) {
_bones.ensureCapacity(_data->getBones().size());
for (size_t i = 0; i < _data->getBones().size(); ++i) {
BoneData *data = _data->getBones()[i];
Bone *bone;
if (data->getParent() == NULL) {
bone = new (__FILE__, __LINE__) Bone(*data, *this, NULL);
} else {
Bone *parent = _bones[data->getParent()->getIndex()];
bone = new (__FILE__, __LINE__) Bone(*data, *this, parent);
parent->getChildren().add(bone);
}
_bones.add(bone);
}
_slots.ensureCapacity(_data->getSlots().size());
_drawOrder.ensureCapacity(_data->getSlots().size());
for (size_t i = 0; i < _data->getSlots().size(); ++i) {
SlotData *data = _data->getSlots()[i];
Bone *bone = _bones[data->getBoneData().getIndex()];
Slot *slot = new (__FILE__, __LINE__) Slot(*data, *bone);
_slots.add(slot);
_drawOrder.add(slot);
}
_ikConstraints.ensureCapacity(_data->getIkConstraints().size());
for (size_t i = 0; i < _data->getIkConstraints().size(); ++i) {
IkConstraintData *data = _data->getIkConstraints()[i];
IkConstraint *constraint = new (__FILE__, __LINE__) IkConstraint(*data, *this);
_ikConstraints.add(constraint);
}
_transformConstraints.ensureCapacity(_data->getTransformConstraints().size());
for (size_t i = 0; i < _data->getTransformConstraints().size(); ++i) {
TransformConstraintData *data = _data->getTransformConstraints()[i];
TransformConstraint *constraint = new (__FILE__, __LINE__) TransformConstraint(*data, *this);
_transformConstraints.add(constraint);
}
_pathConstraints.ensureCapacity(_data->getPathConstraints().size());
for (size_t i = 0; i < _data->getPathConstraints().size(); ++i) {
PathConstraintData *data = _data->getPathConstraints()[i];
PathConstraint *constraint = new (__FILE__, __LINE__) PathConstraint(*data, *this);
_pathConstraints.add(constraint);
}
updateCache();
}
Skeleton::~Skeleton() {
ContainerUtil::cleanUpVectorOfPointers(_bones);
ContainerUtil::cleanUpVectorOfPointers(_slots);
ContainerUtil::cleanUpVectorOfPointers(_ikConstraints);
ContainerUtil::cleanUpVectorOfPointers(_transformConstraints);
ContainerUtil::cleanUpVectorOfPointers(_pathConstraints);
}
void Skeleton::updateCache() {
_updateCache.clear();
_updateCacheReset.clear();
for (size_t i = 0, n = _bones.size(); i < n; ++i) {
Bone *bone = _bones[i];
bone->_sorted = bone->_data.isSkinRequired();
bone->_active = !bone->_sorted;
}
if (_skin) {
Vector<BoneData *> &skinBones = _skin->getBones();
for (size_t i = 0, n = skinBones.size(); i < n; i++) {
Bone *bone = _bones[skinBones[i]->getIndex()];
do {
bone->_sorted = false;
bone->_active = true;
bone = bone->_parent;
} while (bone);
}
}
size_t ikCount = _ikConstraints.size();
size_t transformCount = _transformConstraints.size();
size_t pathCount = _pathConstraints.size();
size_t constraintCount = ikCount + transformCount + pathCount;
size_t i = 0;
continue_outer:
for (; i < constraintCount; ++i) {
for (size_t ii = 0; ii < ikCount; ++ii) {
IkConstraint *constraint = _ikConstraints[ii];
if (constraint->getData().getOrder() == i) {
sortIkConstraint(constraint);
i++;
goto continue_outer;
}
}
for (size_t ii = 0; ii < transformCount; ++ii) {
TransformConstraint *constraint = _transformConstraints[ii];
if (constraint->getData().getOrder() == i) {
sortTransformConstraint(constraint);
i++;
goto continue_outer;
}
}
for (size_t ii = 0; ii < pathCount; ++ii) {
PathConstraint *constraint = _pathConstraints[ii];
if (constraint->getData().getOrder() == i) {
sortPathConstraint(constraint);
i++;
goto continue_outer;
}
}
}
size_t n = _bones.size();
for (i = 0; i < n; ++i) {
sortBone(_bones[i]);
}
}
void Skeleton::printUpdateCache() {
for (size_t i = 0; i < _updateCache.size(); i++) {
Updatable *updatable = _updateCache[i];
if (updatable->getRTTI().isExactly(Bone::rtti)) {
printf("bone %s\n", ((Bone *)updatable)->getData().getName().buffer());
} else if (updatable->getRTTI().isExactly(TransformConstraint::rtti)) {
printf("transform constraint %s\n", ((TransformConstraint *)updatable)->getData().getName().buffer());
} else if (updatable->getRTTI().isExactly(IkConstraint::rtti)) {
printf("ik constraint %s\n", ((IkConstraint *)updatable)->getData().getName().buffer());
} else if (updatable->getRTTI().isExactly(PathConstraint::rtti)) {
printf("path constraint %s\n", ((PathConstraint *)updatable)->getData().getName().buffer());
}
}
}
void Skeleton::updateWorldTransform() {
for (size_t i = 0, n = _updateCacheReset.size(); i < n; ++i) {
Bone *boneP = _updateCacheReset[i];
Bone &bone = *boneP;
bone._ax = bone._x;
bone._ay = bone._y;
bone._arotation = bone._rotation;
bone._ascaleX = bone._scaleX;
bone._ascaleY = bone._scaleY;
bone._ashearX = bone._shearX;
bone._ashearY = bone._shearY;
bone._appliedValid = true;
}
for (size_t i = 0, n = _updateCache.size(); i < n; ++i) {
_updateCache[i]->update();
}
}
void Skeleton::setToSetupPose() {
setBonesToSetupPose();
setSlotsToSetupPose();
}
void Skeleton::setBonesToSetupPose() {
for (size_t i = 0, n = _bones.size(); i < n; ++i) {
_bones[i]->setToSetupPose();
}
for (size_t i = 0, n = _ikConstraints.size(); i < n; ++i) {
IkConstraint *constraintP = _ikConstraints[i];
IkConstraint &constraint = *constraintP;
constraint._bendDirection = constraint._data._bendDirection;
constraint._compress = constraint._data._compress;
constraint._stretch = constraint._data._stretch;
constraint._mix = constraint._data._mix;
constraint._softness = constraint._data._softness;
}
for (size_t i = 0, n = _transformConstraints.size(); i < n; ++i) {
TransformConstraint *constraintP = _transformConstraints[i];
TransformConstraint &constraint = *constraintP;
TransformConstraintData &constraintData = constraint._data;
constraint._rotateMix = constraintData._rotateMix;
constraint._translateMix = constraintData._translateMix;
constraint._scaleMix = constraintData._scaleMix;
constraint._shearMix = constraintData._shearMix;
}
for (size_t i = 0, n = _pathConstraints.size(); i < n; ++i) {
PathConstraint *constraintP = _pathConstraints[i];
PathConstraint &constraint = *constraintP;
PathConstraintData &constraintData = constraint._data;
constraint._position = constraintData._position;
constraint._spacing = constraintData._spacing;
constraint._rotateMix = constraintData._rotateMix;
constraint._translateMix = constraintData._translateMix;
}
}
void Skeleton::setSlotsToSetupPose() {
_drawOrder.clear();
for (size_t i = 0, n = _slots.size(); i < n; ++i) {
_drawOrder.add(_slots[i]);
}
for (size_t i = 0, n = _slots.size(); i < n; ++i) {
_slots[i]->setToSetupPose();
}
}
Bone *Skeleton::findBone(const String &boneName) {
return ContainerUtil::findWithDataName(_bones, boneName);
}
int Skeleton::findBoneIndex(const String &boneName) {
return ContainerUtil::findIndexWithDataName(_bones, boneName);
}
Slot *Skeleton::findSlot(const String &slotName) {
return ContainerUtil::findWithDataName(_slots, slotName);
}
int Skeleton::findSlotIndex(const String &slotName) {
return ContainerUtil::findIndexWithDataName(_slots, slotName);
}
void Skeleton::setSkin(const String &skinName) {
Skin *foundSkin = _data->findSkin(skinName);
assert(foundSkin != NULL);
setSkin(foundSkin);
}
void Skeleton::setSkin(Skin *newSkin) {
if (_skin == newSkin) return;
if (newSkin != NULL) {
if (_skin != NULL) {
Skeleton &thisRef = *this;
newSkin->attachAll(thisRef, *_skin);
} else {
for (size_t i = 0, n = _slots.size(); i < n; ++i) {
Slot *slotP = _slots[i];
Slot &slot = *slotP;
const String &name = slot._data.getAttachmentName();
if (name.length() > 0) {
Attachment *attachment = newSkin->getAttachment(i, name);
if (attachment != NULL) {
slot.setAttachment(attachment);
}
}
}
}
}
_skin = newSkin;
updateCache();
}
Attachment *Skeleton::getAttachment(const String &slotName, const String &attachmentName) {
return getAttachment(_data->findSlotIndex(slotName), attachmentName);
}
Attachment *Skeleton::getAttachment(int slotIndex, const String &attachmentName) {
assert(attachmentName.length() > 0);
if (_skin != NULL) {
Attachment *attachment = _skin->getAttachment(slotIndex, attachmentName);
if (attachment != NULL) {
return attachment;
}
}
return _data->getDefaultSkin() != NULL ? _data->getDefaultSkin()->getAttachment(slotIndex, attachmentName) : NULL;
}
void Skeleton::setAttachment(const String &slotName, const String &attachmentName) {
assert(slotName.length() > 0);
for (size_t i = 0, n = _slots.size(); i < n; ++i) {
Slot *slot = _slots[i];
if (slot->_data.getName() == slotName) {
Attachment *attachment = NULL;
if (attachmentName.length() > 0) {
attachment = getAttachment(i, attachmentName);
assert(attachment != NULL);
}
slot->setAttachment(attachment);
return;
}
}
printf("Slot not found: %s", slotName.buffer());
assert(false);
}
IkConstraint *Skeleton::findIkConstraint(const String &constraintName) {
assert(constraintName.length() > 0);
for (size_t i = 0, n = _ikConstraints.size(); i < n; ++i) {
IkConstraint *ikConstraint = _ikConstraints[i];
if (ikConstraint->_data.getName() == constraintName) {
return ikConstraint;
}
}
return NULL;
}
TransformConstraint *Skeleton::findTransformConstraint(const String &constraintName) {
assert(constraintName.length() > 0);
for (size_t i = 0, n = _transformConstraints.size(); i < n; ++i) {
TransformConstraint *transformConstraint = _transformConstraints[i];
if (transformConstraint->_data.getName() == constraintName) {
return transformConstraint;
}
}
return NULL;
}
PathConstraint *Skeleton::findPathConstraint(const String &constraintName) {
assert(constraintName.length() > 0);
for (size_t i = 0, n = _pathConstraints.size(); i < n; ++i) {
PathConstraint *constraint = _pathConstraints[i];
if (constraint->_data.getName() == constraintName) {
return constraint;
}
}
return NULL;
}
void Skeleton::update(float delta) {
_time += delta;
}
void Skeleton::getBounds(float &outX, float &outY, float &outWidth, float &outHeight, Vector<float> &outVertexBuffer) {
float minX = FLT_MAX;
float minY = FLT_MAX;
float maxX = FLT_MIN;
float maxY = FLT_MIN;
for (size_t i = 0; i < _drawOrder.size(); ++i) {
Slot *slot = _drawOrder[i];
if (!slot->_bone._active) continue;
size_t verticesLength = 0;
Attachment *attachment = slot->getAttachment();
if (attachment != NULL && attachment->getRTTI().instanceOf(RegionAttachment::rtti)) {
RegionAttachment *regionAttachment = static_cast<RegionAttachment *>(attachment);
verticesLength = 8;
if (outVertexBuffer.size() < 8) {
outVertexBuffer.setSize(8, 0);
}
regionAttachment->computeWorldVertices(slot->getBone(), outVertexBuffer, 0);
} else if (attachment != NULL && attachment->getRTTI().instanceOf(MeshAttachment::rtti)) {
MeshAttachment *mesh = static_cast<MeshAttachment *>(attachment);
verticesLength = mesh->getWorldVerticesLength();
if (outVertexBuffer.size() < verticesLength) {
outVertexBuffer.setSize(verticesLength, 0);
}
mesh->computeWorldVertices(*slot, 0, verticesLength, outVertexBuffer, 0);
}
for (size_t ii = 0; ii < verticesLength; ii += 2) {
float vx = outVertexBuffer[ii];
float vy = outVertexBuffer[ii + 1];
minX = MathUtil::min(minX, vx);
minY = MathUtil::min(minY, vy);
maxX = MathUtil::max(maxX, vx);
maxY = MathUtil::max(maxY, vy);
}
}
outX = minX;
outY = minY;
outWidth = maxX - minX;
outHeight = maxY - minY;
}
Bone *Skeleton::getRootBone() {
return _bones.size() == 0 ? NULL : _bones[0];
}
SkeletonData *Skeleton::getData() {
return _data;
}
Vector<Bone *> &Skeleton::getBones() {
return _bones;
}
Vector<Updatable *> &Skeleton::getUpdateCacheList() {
return _updateCache;
}
Vector<Slot *> &Skeleton::getSlots() {
return _slots;
}
Vector<Slot *> &Skeleton::getDrawOrder() {
return _drawOrder;
}
Vector<IkConstraint *> &Skeleton::getIkConstraints() {
return _ikConstraints;
}
Vector<PathConstraint *> &Skeleton::getPathConstraints() {
return _pathConstraints;
}
Vector<TransformConstraint *> &Skeleton::getTransformConstraints() {
return _transformConstraints;
}
Skin *Skeleton::getSkin() {
return _skin;
}
Color &Skeleton::getColor() {
return _color;
}
float Skeleton::getTime() {
return _time;
}
void Skeleton::setTime(float inValue) {
_time = inValue;
}
void Skeleton::setPosition(float x, float y) {
_x = x;
_y = y;
}
float Skeleton::getX() {
return _x;
}
void Skeleton::setX(float inValue) {
_x = inValue;
}
float Skeleton::getY() {
return _y;
}
void Skeleton::setY(float inValue) {
_y = inValue;
}
float Skeleton::getScaleX() {
return _scaleX;
}
void Skeleton::setScaleX(float inValue) {
_scaleX = inValue;
}
float Skeleton::getScaleY() {
return _scaleY * (Bone::isYDown() ? -1 : 1);
}
void Skeleton::setScaleY(float inValue) {
_scaleY = inValue;
}
void Skeleton::sortIkConstraint(IkConstraint *constraint) {
constraint->_active = constraint->_target->_active && (!constraint->_data.isSkinRequired() || (_skin && _skin->_constraints.contains(&constraint->_data)));
if (!constraint->_active) return;
Bone *target = constraint->getTarget();
sortBone(target);
Vector<Bone *> &constrained = constraint->getBones();
Bone *parent = constrained[0];
sortBone(parent);
if (constrained.size() > 1) {
Bone *child = constrained[constrained.size() - 1];
if (!_updateCache.contains(child)) _updateCacheReset.add(child);
}
_updateCache.add(constraint);
sortReset(parent->getChildren());
constrained[constrained.size() - 1]->_sorted = true;
}
void Skeleton::sortPathConstraint(PathConstraint *constraint) {
constraint->_active = constraint->_target->_bone._active && (!constraint->_data.isSkinRequired() || (_skin && _skin->_constraints.contains(&constraint->_data)));
if (!constraint->_active) return;
Slot *slot = constraint->getTarget();
int slotIndex = slot->getData().getIndex();
Bone &slotBone = slot->getBone();
if (_skin != NULL) sortPathConstraintAttachment(_skin, slotIndex, slotBone);
if (_data->_defaultSkin != NULL && _data->_defaultSkin != _skin)
sortPathConstraintAttachment(_data->_defaultSkin, slotIndex, slotBone);
for (size_t ii = 0, nn = _data->_skins.size(); ii < nn; ii++)
sortPathConstraintAttachment(_data->_skins[ii], slotIndex, slotBone);
Attachment *attachment = slot->getAttachment();
if (attachment != NULL && attachment->getRTTI().instanceOf(PathAttachment::rtti))
sortPathConstraintAttachment(attachment, slotBone);
Vector<Bone *> &constrained = constraint->getBones();
size_t boneCount = constrained.size();
for (size_t i = 0; i < boneCount; ++i) {
sortBone(constrained[i]);
}
_updateCache.add(constraint);
for (size_t i = 0; i < boneCount; i++)
sortReset(constrained[i]->getChildren());
for (size_t i = 0; i < boneCount; i++)
constrained[i]->_sorted = true;
}
void Skeleton::sortTransformConstraint(TransformConstraint *constraint) {
constraint->_active = constraint->_target->_active && (!constraint->_data.isSkinRequired() || (_skin && _skin->_constraints.contains(&constraint->_data)));
if (!constraint->_active) return;
sortBone(constraint->getTarget());
Vector<Bone *> &constrained = constraint->getBones();
size_t boneCount = constrained.size();
if (constraint->_data.isLocal()) {
for (size_t i = 0; i < boneCount; i++) {
Bone *child = constrained[i];
sortBone(child->getParent());
if (!_updateCache.contains(child)) _updateCacheReset.add(child);
}
} else {
for (size_t i = 0; i < boneCount; ++i) {
sortBone(constrained[i]);
}
}
_updateCache.add(constraint);
for (size_t i = 0; i < boneCount; ++i)
sortReset(constrained[i]->getChildren());
for (size_t i = 0; i < boneCount; ++i)
constrained[i]->_sorted = true;
}
void Skeleton::sortPathConstraintAttachment(Skin *skin, size_t slotIndex, Bone &slotBone) {
Skin::AttachmentMap::Entries attachments = skin->getAttachments();
while (attachments.hasNext()) {
Skin::AttachmentMap::Entry entry = attachments.next();
if (entry._slotIndex == slotIndex) {
Attachment *value = entry._attachment;
sortPathConstraintAttachment(value, slotBone);
}
}
}
void Skeleton::sortPathConstraintAttachment(Attachment *attachment, Bone &slotBone) {
if (attachment == NULL || !attachment->getRTTI().instanceOf(PathAttachment::rtti)) return;
Vector<size_t> &pathBones = static_cast<PathAttachment *>(attachment)->getBones();
if (pathBones.size() == 0)
sortBone(&slotBone);
else {
for (size_t i = 0, n = pathBones.size(); i < n;) {
size_t nn = pathBones[i++];
nn += i;
while (i < nn) {
sortBone(_bones[pathBones[i++]]);
}
}
}
}
void Skeleton::sortBone(Bone *bone) {
if (bone->_sorted) return;
Bone *parent = bone->_parent;
if (parent != NULL) sortBone(parent);
bone->_sorted = true;
_updateCache.add(bone);
}
void Skeleton::sortReset(Vector<Bone *> &bones) {
for (size_t i = 0, n = bones.size(); i < n; ++i) {
Bone *bone = bones[i];
if (!bone->_active) continue;
if (bone->_sorted) sortReset(bone->getChildren());
bone->_sorted = false;
}
}

View File

@@ -0,0 +1,243 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_Skeleton_h
#define Spine_Skeleton_h
#include <spine/Color.h>
#include <spine/MathUtil.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
#include <spine/Vector.h>
namespace spine {
class SkeletonData;
class Bone;
class Updatable;
class Slot;
class IkConstraint;
class PathConstraint;
class TransformConstraint;
class Skin;
class Attachment;
class SP_API Skeleton : public SpineObject {
friend class AnimationState;
friend class SkeletonBounds;
friend class SkeletonClipping;
friend class AttachmentTimeline;
friend class ColorTimeline;
friend class DeformTimeline;
friend class DrawOrderTimeline;
friend class EventTimeline;
friend class IkConstraintTimeline;
friend class PathConstraintMixTimeline;
friend class PathConstraintPositionTimeline;
friend class PathConstraintSpacingTimeline;
friend class ScaleTimeline;
friend class ShearTimeline;
friend class TransformConstraintTimeline;
friend class TranslateTimeline;
friend class TwoColorTimeline;
public:
explicit Skeleton(SkeletonData *skeletonData);
~Skeleton();
/// Caches information about bones and constraints. Must be called if bones, constraints or weighted path attachments are added
/// or removed.
void updateCache();
void printUpdateCache();
/// Updates the world transform for each bone and applies constraints.
void updateWorldTransform();
/// Sets the bones, constraints, and slots to their setup pose values.
void setToSetupPose();
/// Sets the bones and constraints to their setup pose values.
void setBonesToSetupPose();
void setSlotsToSetupPose();
/// @return May be NULL.
Bone *findBone(const String &boneName);
/// @return -1 if the bone was not found.
int findBoneIndex(const String &boneName);
/// @return May be NULL.
Slot *findSlot(const String &slotName);
/// @return -1 if the bone was not found.
int findSlotIndex(const String &slotName);
/// Sets a skin by name (see setSkin).
void setSkin(const String &skinName);
/// Attachments from the new skin are attached if the corresponding attachment from the old skin was attached.
/// If there was no old skin, each slot's setup mode attachment is attached from the new skin.
/// After changing the skin, the visible attachments can be reset to those attached in the setup pose by calling
/// See Skeleton::setSlotsToSetupPose()
/// Also, often AnimationState::apply(Skeleton&) is called before the next time the
/// skeleton is rendered to allow any attachment keys in the current animation(s) to hide or show attachments from the new skin.
/// @param newSkin May be NULL.
void setSkin(Skin *newSkin);
/// @return May be NULL.
Attachment *getAttachment(const String &slotName, const String &attachmentName);
/// @return May be NULL.
Attachment *getAttachment(int slotIndex, const String &attachmentName);
/// @param attachmentName May be empty.
void setAttachment(const String &slotName, const String &attachmentName);
/// @return May be NULL.
IkConstraint *findIkConstraint(const String &constraintName);
/// @return May be NULL.
TransformConstraint *findTransformConstraint(const String &constraintName);
/// @return May be NULL.
PathConstraint *findPathConstraint(const String &constraintName);
void update(float delta);
/// Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose.
/// @param outX The horizontal distance between the skeleton origin and the left side of the AABB.
/// @param outY The vertical distance between the skeleton origin and the bottom side of the AABB.
/// @param outWidth The width of the AABB
/// @param outHeight The height of the AABB.
/// @param outVertexBuffer Reference to hold a Vector of floats. This method will assign it with new floats as needed.
void getBounds(float &outX, float &outY, float &outWidth, float &outHeight, Vector<float> &outVertexBuffer);
Bone *getRootBone();
SkeletonData *getData();
Vector<Bone *> &getBones();
Vector<Updatable *> &getUpdateCacheList();
Vector<Slot *> &getSlots();
Vector<Slot *> &getDrawOrder();
Vector<IkConstraint *> &getIkConstraints();
Vector<PathConstraint *> &getPathConstraints();
Vector<TransformConstraint *> &getTransformConstraints();
Skin *getSkin();
Color &getColor();
float getTime();
void setTime(float inValue);
void setPosition(float x, float y);
float getX();
void setX(float inValue);
float getY();
void setY(float inValue);
float getScaleX();
void setScaleX(float inValue);
float getScaleY();
void setScaleY(float inValue);
private:
SkeletonData *_data;
Vector<Bone *> _bones;
Vector<Slot *> _slots;
Vector<Slot *> _drawOrder;
Vector<IkConstraint *> _ikConstraints;
Vector<TransformConstraint *> _transformConstraints;
Vector<PathConstraint *> _pathConstraints;
Vector<Updatable *> _updateCache;
Vector<Bone *> _updateCacheReset;
Skin *_skin;
Color _color;
float _time;
float _scaleX, _scaleY;
float _x, _y;
void sortIkConstraint(IkConstraint *constraint);
void sortPathConstraint(PathConstraint *constraint);
void sortTransformConstraint(TransformConstraint *constraint);
void sortPathConstraintAttachment(Skin *skin, size_t slotIndex, Bone &slotBone);
void sortPathConstraintAttachment(Attachment *attachment, Bone &slotBone);
void sortBone(Bone *bone);
static void sortReset(Vector<Bone *> &bones);
};
} // namespace spine
#endif /* Spine_Skeleton_h */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,131 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_SkeletonBinary_h
#define Spine_SkeletonBinary_h
#include <spine/Color.h>
#include <spine/SpineObject.h>
#include <spine/SpineString.h>
#include <spine/TransformMode.h>
#include <spine/Vector.h>
namespace spine {
class SkeletonData;
class Atlas;
class AttachmentLoader;
class LinkedMesh;
class Skin;
class Attachment;
class VertexAttachment;
class Animation;
class CurveTimeline;
class SP_API SkeletonBinary : public SpineObject {
public:
static const int BONE_ROTATE;
static const int BONE_TRANSLATE;
static const int BONE_SCALE;
static const int BONE_SHEAR;
static const int SLOT_ATTACHMENT;
static const int SLOT_COLOR;
static const int SLOT_TWO_COLOR;
static const int PATH_POSITION;
static const int PATH_SPACING;
static const int PATH_MIX;
static const int CURVE_LINEAR;
static const int CURVE_STEPPED;
static const int CURVE_BEZIER;
explicit SkeletonBinary(Atlas* atlasArray);
explicit SkeletonBinary(AttachmentLoader* attachmentLoader);
~SkeletonBinary();
SkeletonData* readSkeletonData(const unsigned char* binary, int length);
SkeletonData* readSkeletonDataFile(const String& path);
void setScale(float scale) { _scale = scale; }
String& getError() { return _error; }
private:
struct DataInput : public SpineObject {
const unsigned char* cursor;
const unsigned char* end;
};
AttachmentLoader* _attachmentLoader;
Vector<LinkedMesh*> _linkedMeshes;
String _error;
float _scale;
const bool _ownsLoader;
void setError(const char* value1, const char* value2);
char* readString(DataInput* input);
char* readStringRef(DataInput* input, SkeletonData* skeletonData);
float readFloat(DataInput* input);
unsigned char readByte(DataInput* input);
signed char readSByte(DataInput* input);
bool readBoolean(DataInput* input);
int readInt(DataInput* input);
void readColor(DataInput* input, Color& color);
int readVarint(DataInput* input, bool optimizePositive);
Skin* readSkin(DataInput* input, bool defaultSkin, SkeletonData* skeletonData, bool nonessential);
Attachment* readAttachment(DataInput* input, Skin* skin, int slotIndex, const String& attachmentName, SkeletonData* skeletonData, bool nonessential);
void readVertices(DataInput* input, VertexAttachment* attachment, int vertexCount);
void readFloatArray(DataInput* input, int n, float scale, Vector<float>& array);
void readShortArray(DataInput* input, Vector<unsigned short>& array);
Animation* readAnimation(const String& name, DataInput* input, SkeletonData* skeletonData);
void readCurve(DataInput* input, int frameIndex, CurveTimeline* timeline);
};
} // namespace spine
#endif /* Spine_SkeletonBinary_h */

View File

@@ -0,0 +1,223 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifdef SPINE_UE4
#include "SpinePluginPrivatePCH.h"
#endif
#include <spine/SkeletonBounds.h>
#include <spine/Bone.h>
#include <spine/BoundingBoxAttachment.h>
#include <spine/Skeleton.h>
#include <spine/Slot.h>
#include <float.h>
using namespace spine;
SkeletonBounds::SkeletonBounds() : _minX(0), _minY(0), _maxX(0), _maxY(0) {
}
void SkeletonBounds::update(Skeleton &skeleton, bool updateAabb) {
Vector<Slot *> &slots = skeleton._slots;
size_t slotCount = slots.size();
_boundingBoxes.clear();
for (size_t i = 0, n = _polygons.size(); i < n; ++i) {
_polygonPool.add(_polygons[i]);
}
_polygons.clear();
for (size_t i = 0; i < slotCount; i++) {
Slot *slot = slots[i];
if (!slot->getBone().isActive()) continue;
Attachment *attachment = slot->getAttachment();
if (attachment == NULL || !attachment->getRTTI().instanceOf(BoundingBoxAttachment::rtti)) continue;
BoundingBoxAttachment *boundingBox = static_cast<BoundingBoxAttachment *>(attachment);
_boundingBoxes.add(boundingBox);
spine::Polygon *polygonP = NULL;
size_t poolCount = _polygonPool.size();
if (poolCount > 0) {
polygonP = _polygonPool[poolCount - 1];
_polygonPool.removeAt(poolCount - 1);
} else
polygonP = new (__FILE__, __LINE__) Polygon();
_polygons.add(polygonP);
Polygon &polygon = *polygonP;
size_t count = boundingBox->getWorldVerticesLength();
polygon._count = count;
if (polygon._vertices.size() < count) {
polygon._vertices.setSize(count, 0);
}
boundingBox->computeWorldVertices(*slot, polygon._vertices);
}
if (updateAabb)
aabbCompute();
else {
_minX = FLT_MIN;
_minY = FLT_MIN;
_maxX = FLT_MAX;
_maxY = FLT_MAX;
}
}
bool SkeletonBounds::aabbcontainsPoint(float x, float y) {
return x >= _minX && x <= _maxX && y >= _minY && y <= _maxY;
}
bool SkeletonBounds::aabbintersectsSegment(float x1, float y1, float x2, float y2) {
float minX = _minX;
float minY = _minY;
float maxX = _maxX;
float maxY = _maxY;
if ((x1 <= minX && x2 <= minX) || (y1 <= minY && y2 <= minY) || (x1 >= maxX && x2 >= maxX) ||
(y1 >= maxY && y2 >= maxY)) {
return false;
}
float m = (y2 - y1) / (x2 - x1);
float y = m * (minX - x1) + y1;
if (y > minY && y < maxY) return true;
y = m * (maxX - x1) + y1;
if (y > minY && y < maxY) return true;
float x = (minY - y1) / m + x1;
if (x > minX && x < maxX) return true;
x = (maxY - y1) / m + x1;
if (x > minX && x < maxX) return true;
return false;
}
bool SkeletonBounds::aabbIntersectsSkeleton(SkeletonBounds bounds) {
return _minX < bounds._maxX && _maxX > bounds._minX && _minY < bounds._maxY && _maxY > bounds._minY;
}
bool SkeletonBounds::containsPoint(spine::Polygon *polygon, float x, float y) {
Vector<float> &vertices = polygon->_vertices;
int nn = polygon->_count;
int prevIndex = nn - 2;
bool inside = false;
for (int ii = 0; ii < nn; ii += 2) {
float vertexY = vertices[ii + 1];
float prevY = vertices[prevIndex + 1];
if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) {
float vertexX = vertices[ii];
if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x) {
inside = !inside;
}
}
prevIndex = ii;
}
return inside;
}
BoundingBoxAttachment *SkeletonBounds::containsPoint(float x, float y) {
for (size_t i = 0, n = _polygons.size(); i < n; ++i)
if (containsPoint(_polygons[i], x, y)) return _boundingBoxes[i];
return NULL;
}
BoundingBoxAttachment *SkeletonBounds::intersectsSegment(float x1, float y1, float x2, float y2) {
for (size_t i = 0, n = _polygons.size(); i < n; ++i)
if (intersectsSegment(_polygons[i], x1, y1, x2, y2)) return _boundingBoxes[i];
return NULL;
}
bool SkeletonBounds::intersectsSegment(spine::Polygon *polygon, float x1, float y1, float x2, float y2) {
Vector<float> &vertices = polygon->_vertices;
size_t nn = polygon->_count;
float width12 = x1 - x2, height12 = y1 - y2;
float det1 = x1 * y2 - y1 * x2;
float x3 = vertices[nn - 2], y3 = vertices[nn - 1];
for (size_t ii = 0; ii < nn; ii += 2) {
float x4 = vertices[ii], y4 = vertices[ii + 1];
float det2 = x3 * y4 - y3 * x4;
float width34 = x3 - x4, height34 = y3 - y4;
float det3 = width12 * height34 - height12 * width34;
float x = (det1 * width34 - width12 * det2) / det3;
if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) {
float y = (det1 * height34 - height12 * det2) / det3;
if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1))) {
return true;
}
}
x3 = x4;
y3 = y4;
}
return false;
}
spine::Polygon *SkeletonBounds::getPolygon(BoundingBoxAttachment *attachment) {
int index = _boundingBoxes.indexOf(attachment);
return index == -1 ? NULL : _polygons[index];
}
float SkeletonBounds::getWidth() {
return _maxX - _minX;
}
float SkeletonBounds::getHeight() {
return _maxY - _minY;
}
void SkeletonBounds::aabbCompute() {
float minX = FLT_MIN;
float minY = FLT_MIN;
float maxX = FLT_MAX;
float maxY = FLT_MAX;
for (size_t i = 0, n = _polygons.size(); i < n; ++i) {
spine::Polygon *polygon = _polygons[i];
Vector<float> &vertices = polygon->_vertices;
for (int ii = 0, nn = polygon->_count; ii < nn; ii += 2) {
float x = vertices[ii];
float y = vertices[ii + 1];
minX = MathUtil::min(minX, x);
minY = MathUtil::min(minY, y);
maxX = MathUtil::max(maxX, x);
maxY = MathUtil::max(maxY, y);
}
}
_minX = minX;
_minY = minY;
_maxX = maxX;
_maxY = maxY;
}

View File

@@ -0,0 +1,104 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_SkeletonBounds_h
#define Spine_SkeletonBounds_h
#include <spine/SpineObject.h>
#include <spine/Vector.h>
namespace spine {
class Skeleton;
class BoundingBoxAttachment;
class Polygon;
/// Collects each BoundingBoxAttachment that is visible and computes the world vertices for its polygon.
/// The polygon vertices are provided along with convenience methods for doing hit detection.
class SP_API SkeletonBounds : public SpineObject {
public:
SkeletonBounds();
/// Clears any previous polygons, finds all visible bounding box attachments,
/// and computes the world vertices for each bounding box's polygon.
/// @param skeleton The skeleton.
/// @param updateAabb
/// If true, the axis aligned bounding box containing all the polygons is computed.
/// If false, the SkeletonBounds AABB methods will always return true.
///
void update(Skeleton& skeleton, bool updateAabb);
/// Returns true if the axis aligned bounding box contains the point.
bool aabbcontainsPoint(float x, float y);
/// Returns true if the axis aligned bounding box intersects the line segment.
bool aabbintersectsSegment(float x1, float y1, float x2, float y2);
/// Returns true if the axis aligned bounding box intersects the axis aligned bounding box of the specified bounds.
bool aabbIntersectsSkeleton(SkeletonBounds bounds);
/// Returns true if the polygon contains the point.
bool containsPoint(Polygon* polygon, float x, float y);
/// Returns the first bounding box attachment that contains the point, or NULL. When doing many checks, it is usually more
/// efficient to only call this method if {@link #aabbcontainsPoint(float, float)} returns true.
BoundingBoxAttachment* containsPoint(float x, float y);
/// Returns the first bounding box attachment that contains the line segment, or NULL. When doing many checks, it is usually
/// more efficient to only call this method if {@link #aabbintersectsSegment(float, float, float, float)} returns true.
BoundingBoxAttachment* intersectsSegment(float x1, float y1, float x2, float y2);
/// Returns true if the polygon contains the line segment.
bool intersectsSegment(Polygon* polygon, float x1, float y1, float x2, float y2);
Polygon* getPolygon(BoundingBoxAttachment* attachment);
float getWidth();
float getHeight();
private:
Vector<Polygon*> _polygonPool;
Vector<BoundingBoxAttachment*> _boundingBoxes;
Vector<Polygon*> _polygons;
float _minX, _minY, _maxX, _maxY;
void aabbCompute();
};
class Polygon : public SpineObject {
public:
Vector<float> _vertices;
int _count;
Polygon() : _count(0) {
_vertices.ensureCapacity(16);
}
};
} // namespace spine
#endif /* Spine_SkeletonBounds_h */

Some files were not shown because too many files have changed in this diff Show More