This commit is contained in:
Stephen Gowen 2017-10-24 20:54:27 -04:00
parent 8ef11955a7
commit 873b4d397f
8 changed files with 163 additions and 39 deletions

View File

@ -50,6 +50,7 @@ namespace Spine
friend class RotateTimeline; friend class RotateTimeline;
friend class IkConstraint; friend class IkConstraint;
friend class TransformConstraint; friend class TransformConstraint;
friend class VertexAttachment;
public: public:
static void setYDown(bool inValue); static void setYDown(bool inValue);

View File

@ -39,6 +39,8 @@ namespace Spine
{ {
class BoneData class BoneData
{ {
friend class RotateTimeline;
public: public:
BoneData(int index, std::string name, BoneData* parent = NULL); BoneData(int index, std::string name, BoneData* parent = NULL);

View File

@ -0,0 +1,60 @@
/******************************************************************************
* 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_PathAttachment_h
#define Spine_PathAttachment_h
#include <spine/VertexAttachment.h>
namespace Spine
{
class PathAttachment : public VertexAttachment
{
public:
PathAttachment(std::string name) : VertexAttachment(name)
{
// Empty
}
/// The length in the setup pose from the start of the path to the end of each curve.
float[] Lengths { return lengths; }
set { lengths = value; }
bool Closed { return closed; }
set { closed = value; }
bool ConstantSpeed { return constantSpeed; }
set { constantSpeed = value; }
private:
float[] lengths;
bool closed, constantSpeed;
};
}
#endif /* Spine_PathAttachment_h */

View File

@ -44,14 +44,16 @@ namespace Spine
class Slot class Slot
{ {
friend class VertexAttachment;
public: public:
Slot(SlotData& data, Bone& bone); Slot(SlotData& data, Bone& bone);
void setToSetupPose(); void setToSetupPose();
const SlotData& getSlotData(); SlotData& getSlotData();
const Bone& getBone(); Bone& getBone();
const Skeleton& getSkeleton(); Skeleton& getSkeleton();
float getR(); float getR();
void setR(float inValue); void setR(float inValue);
@ -82,9 +84,9 @@ namespace Spine
void setAttachmentVertices(Vector<float> inValue); void setAttachmentVertices(Vector<float> inValue);
private: private:
const SlotData& _slotData; SlotData& _slotData;
const Bone& _bone; Bone& _bone;
const Skeleton& _skeleton; Skeleton& _skeleton;
float _r, _g, _b, _a; float _r, _g, _b, _a;
float _r2, _g2, _b2; float _r2, _g2, _b2;
bool _hasSecondColor; bool _hasSecondColor;

View File

@ -0,0 +1,34 @@
/******************************************************************************
* 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.
*****************************************************************************/
namespace Spine
{
// TODO
}

View File

@ -34,7 +34,9 @@
#include <spine/Event.h> #include <spine/Event.h>
#include <spine/Bone.h> #include <spine/Bone.h>
#include <spine/BoneData.h>
#include <spine/Animation.h> #include <spine/Animation.h>
#include <spine/TimelineType.h>
namespace Spine namespace Spine
{ {
@ -45,20 +47,29 @@ namespace Spine
void RotateTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction) void RotateTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction)
{ {
Bone* bone = skeleton.getBones().at(_boneIndex); Bone* bone = skeleton.getBones()[_boneIndex];
if (time < _frames[0]) if (time < _frames[0])
{ {
switch (pose) switch (pose)
{ {
case MixPose_Setup: case MixPose_Setup:
bone->_rotation = bone->_data->_rotation; {
return; bone->_rotation = bone->_data._rotation;
break;
}
case MixPose_Current: case MixPose_Current:
float rr = bone->_data->_rotation - bone->_rotation; {
float rr = bone->_data._rotation - bone->_rotation;
rr -= (16384 - (int)(16384.499999999996 - rr / 360)) * 360; rr -= (16384 - (int)(16384.499999999996 - rr / 360)) * 360;
bone->_rotation += rr * alpha; bone->_rotation += rr * alpha;
return; break;
}
case MixPose_CurrentLayered:
{
// TODO?
break;
}
} }
return; return;
@ -69,11 +80,11 @@ namespace Spine
// Time is after last frame. // Time is after last frame.
if (pose == MixPose_Setup) if (pose == MixPose_Setup)
{ {
bone->_rotation = bone->_data->_rotation + _frames[_frames.size() + PREV_ROTATION] * alpha; bone->_rotation = bone->_data._rotation + _frames[_frames.size() + PREV_ROTATION] * alpha;
} }
else else
{ {
float rr = bone->_data->_rotation + _frames[_frames.size() + PREV_ROTATION] - bone->_rotation; float rr = bone->_data._rotation + _frames[_frames.size() + PREV_ROTATION] - bone->_rotation;
rr -= (16384 - (int)(16384.499999999996 - rr / 360)) * 360; // Wrap within -180 and 180. rr -= (16384 - (int)(16384.499999999996 - rr / 360)) * 360; // Wrap within -180 and 180.
bone->_rotation += rr * alpha; bone->_rotation += rr * alpha;
} }
@ -94,11 +105,11 @@ namespace Spine
if (pose == MixPose_Setup) if (pose == MixPose_Setup)
{ {
r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360;
bone->_rotation = bone->_data->_rotation + r * alpha; bone->_rotation = bone->_data._rotation + r * alpha;
} }
else else
{ {
r = bone->_data->_rotation + r - bone->_rotation; r = bone->_data._rotation + r - bone->_rotation;
r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360;
bone->_rotation += r * alpha; bone->_rotation += r * alpha;
} }

View File

@ -74,17 +74,17 @@ namespace Spine
} }
} }
const SlotData& Slot::getSlotData() SlotData& Slot::getSlotData()
{ {
return _slotData; return _slotData;
} }
const Bone& Slot::getBone() Bone& Slot::getBone()
{ {
return _bone; return _bone;
} }
const Skeleton& Slot::getSkeleton() Skeleton& Slot::getSkeleton()
{ {
return _skeleton; return _skeleton;
} }

View File

@ -32,6 +32,9 @@
#include <spine/Slot.h> #include <spine/Slot.h>
#include <spine/Bone.h>
#include <spine/Skeleton.h>
namespace Spine namespace Spine
{ {
VertexAttachment::VertexAttachment(std::string name) : Attachment(name), _id(getNextID()), _worldVerticesLength(0) VertexAttachment::VertexAttachment(std::string name) : Attachment(name), _id(getNextID()), _worldVerticesLength(0)
@ -47,19 +50,25 @@ namespace Spine
void VertexAttachment::computeWorldVertices(Slot& slot, int start, int count, Vector<float>& worldVertices, int offset, int stride) void VertexAttachment::computeWorldVertices(Slot& slot, int start, int count, Vector<float>& worldVertices, int offset, int stride)
{ {
count = offset + (count >> 1) * stride; count = offset + (count >> 1) * stride;
Skeleton skeleton = slot.bone.skeleton; Skeleton& skeleton = slot._bone._skeleton;
var deformArray = slot.attachmentVertices; Vector<float>& deformArray = slot.getAttachmentVertices();
Vector<float> vertices = _vertices; Vector<float>& vertices = _vertices;
Vector<int> bones = _bones; Vector<int>& bones = _bones;
if (bones == NULL) if (bones.size() == 0)
{ {
if (deformArray.Count > 0) vertices = deformArray.Items; if (deformArray.size() > 0)
Bone bone = slot.bone; {
float x = bone.worldX, y = bone.worldY; vertices = deformArray;
float a = bone.a, b = bone.b, c = bone.c, d = bone.d; }
Bone& bone = slot._bone;
float x = bone._worldX;
float y = bone._worldY;
float a = bone._a, b = bone._b, c = bone._c, d = bone._d;
for (int vv = start, w = offset; w < count; vv += 2, w += stride) for (int vv = start, w = offset; w < count; vv += 2, w += stride)
{ {
float vx = vertices[vv], vy = vertices[vv + 1]; float vx = vertices[vv];
float vy = vertices[vv + 1];
worldVertices[w] = vx * a + vy * b + x; worldVertices[w] = vx * a + vy * b + x;
worldVertices[w + 1] = vx * c + vy * d + y; worldVertices[w + 1] = vx * c + vy * d + y;
} }
@ -74,8 +83,8 @@ namespace Spine
skip += n; skip += n;
} }
var skeletonBones = skeleton.bones.Items; Vector<Bone*>& skeletonBones = skeleton.getBones();
if (deformArray.Count == 0) if (deformArray.size() == 0)
{ {
for (int w = offset, b = skip * 3; w < count; w += stride) for (int w = offset, b = skip * 3; w < count; w += stride)
{ {
@ -84,10 +93,13 @@ namespace Spine
n += v; n += v;
for (; v < n; v++, b += 3) for (; v < n; v++, b += 3)
{ {
Bone bone = skeletonBones[bones[v]]; Bone* boneP = skeletonBones[bones[v]];
float vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2]; Bone bone = *boneP;
wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight; float vx = vertices[b];
wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight; float vy = vertices[b + 1];
float weight = vertices[b + 2];
wx += (vx * bone._a + vy * bone._b + bone._worldX) * weight;
wy += (vx * bone._c + vy * bone._d + bone._worldY) * weight;
} }
worldVertices[w] = wx; worldVertices[w] = wx;
worldVertices[w + 1] = wy; worldVertices[w + 1] = wy;
@ -95,7 +107,6 @@ namespace Spine
} }
else else
{ {
Vector<float> deform = deformArray.Items;
for (int w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) for (int w = offset, b = skip * 3, f = skip << 1; w < count; w += stride)
{ {
float wx = 0, wy = 0; float wx = 0, wy = 0;
@ -103,10 +114,13 @@ namespace Spine
n += v; n += v;
for (; v < n; v++, b += 3, f += 2) for (; v < n; v++, b += 3, f += 2)
{ {
Bone bone = skeletonBones[bones[v]]; Bone* boneP = skeletonBones[bones[v]];
float vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2]; Bone bone = *boneP;
wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight; float vx = vertices[b] + deformArray[f];
wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight; float vy = vertices[b + 1] + deformArray[f + 1];
float weight = vertices[b + 2];
wx += (vx * bone._a + vy * bone._b + bone._worldX) * weight;
wy += (vx * bone._c + vy * bone._d + bone._worldY) * weight;
} }
worldVertices[w] = wx; worldVertices[w] = wx;
worldVertices[w + 1] = wy; worldVertices[w + 1] = wy;