mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-05 23:05:01 +08:00
wip
This commit is contained in:
parent
8ef11955a7
commit
873b4d397f
@ -50,6 +50,7 @@ namespace Spine
|
||||
friend class RotateTimeline;
|
||||
friend class IkConstraint;
|
||||
friend class TransformConstraint;
|
||||
friend class VertexAttachment;
|
||||
|
||||
public:
|
||||
static void setYDown(bool inValue);
|
||||
|
||||
@ -39,6 +39,8 @@ namespace Spine
|
||||
{
|
||||
class BoneData
|
||||
{
|
||||
friend class RotateTimeline;
|
||||
|
||||
public:
|
||||
BoneData(int index, std::string name, BoneData* parent = NULL);
|
||||
|
||||
|
||||
60
spine-cpp/spine-cpp/include/spine/PathAttachment.h
Normal file
60
spine-cpp/spine-cpp/include/spine/PathAttachment.h
Normal 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 */
|
||||
@ -44,14 +44,16 @@ namespace Spine
|
||||
|
||||
class Slot
|
||||
{
|
||||
friend class VertexAttachment;
|
||||
|
||||
public:
|
||||
Slot(SlotData& data, Bone& bone);
|
||||
|
||||
void setToSetupPose();
|
||||
|
||||
const SlotData& getSlotData();
|
||||
const Bone& getBone();
|
||||
const Skeleton& getSkeleton();
|
||||
SlotData& getSlotData();
|
||||
Bone& getBone();
|
||||
Skeleton& getSkeleton();
|
||||
|
||||
float getR();
|
||||
void setR(float inValue);
|
||||
@ -82,9 +84,9 @@ namespace Spine
|
||||
void setAttachmentVertices(Vector<float> inValue);
|
||||
|
||||
private:
|
||||
const SlotData& _slotData;
|
||||
const Bone& _bone;
|
||||
const Skeleton& _skeleton;
|
||||
SlotData& _slotData;
|
||||
Bone& _bone;
|
||||
Skeleton& _skeleton;
|
||||
float _r, _g, _b, _a;
|
||||
float _r2, _g2, _b2;
|
||||
bool _hasSecondColor;
|
||||
|
||||
34
spine-cpp/spine-cpp/src/spine/PathAttachment.cpp
Normal file
34
spine-cpp/spine-cpp/src/spine/PathAttachment.cpp
Normal 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
|
||||
}
|
||||
@ -34,7 +34,9 @@
|
||||
#include <spine/Event.h>
|
||||
|
||||
#include <spine/Bone.h>
|
||||
#include <spine/BoneData.h>
|
||||
#include <spine/Animation.h>
|
||||
#include <spine/TimelineType.h>
|
||||
|
||||
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)
|
||||
{
|
||||
Bone* bone = skeleton.getBones().at(_boneIndex);
|
||||
Bone* bone = skeleton.getBones()[_boneIndex];
|
||||
|
||||
if (time < _frames[0])
|
||||
{
|
||||
switch (pose)
|
||||
{
|
||||
case MixPose_Setup:
|
||||
bone->_rotation = bone->_data->_rotation;
|
||||
return;
|
||||
{
|
||||
bone->_rotation = bone->_data._rotation;
|
||||
break;
|
||||
}
|
||||
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;
|
||||
bone->_rotation += rr * alpha;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case MixPose_CurrentLayered:
|
||||
{
|
||||
// TODO?
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
@ -69,11 +80,11 @@ namespace Spine
|
||||
// Time is after last frame.
|
||||
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
|
||||
{
|
||||
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.
|
||||
bone->_rotation += rr * alpha;
|
||||
}
|
||||
@ -94,11 +105,11 @@ namespace Spine
|
||||
if (pose == MixPose_Setup)
|
||||
{
|
||||
r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360;
|
||||
bone->_rotation = bone->_data->_rotation + r * alpha;
|
||||
bone->_rotation = bone->_data._rotation + r * alpha;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = bone->_data->_rotation + r - bone->_rotation;
|
||||
r = bone->_data._rotation + r - bone->_rotation;
|
||||
r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360;
|
||||
bone->_rotation += r * alpha;
|
||||
}
|
||||
|
||||
@ -74,17 +74,17 @@ namespace Spine
|
||||
}
|
||||
}
|
||||
|
||||
const SlotData& Slot::getSlotData()
|
||||
SlotData& Slot::getSlotData()
|
||||
{
|
||||
return _slotData;
|
||||
}
|
||||
|
||||
const Bone& Slot::getBone()
|
||||
Bone& Slot::getBone()
|
||||
{
|
||||
return _bone;
|
||||
}
|
||||
|
||||
const Skeleton& Slot::getSkeleton()
|
||||
Skeleton& Slot::getSkeleton()
|
||||
{
|
||||
return _skeleton;
|
||||
}
|
||||
|
||||
@ -32,6 +32,9 @@
|
||||
|
||||
#include <spine/Slot.h>
|
||||
|
||||
#include <spine/Bone.h>
|
||||
#include <spine/Skeleton.h>
|
||||
|
||||
namespace Spine
|
||||
{
|
||||
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)
|
||||
{
|
||||
count = offset + (count >> 1) * stride;
|
||||
Skeleton skeleton = slot.bone.skeleton;
|
||||
var deformArray = slot.attachmentVertices;
|
||||
Vector<float> vertices = _vertices;
|
||||
Vector<int> bones = _bones;
|
||||
if (bones == NULL)
|
||||
Skeleton& skeleton = slot._bone._skeleton;
|
||||
Vector<float>& deformArray = slot.getAttachmentVertices();
|
||||
Vector<float>& vertices = _vertices;
|
||||
Vector<int>& bones = _bones;
|
||||
if (bones.size() == 0)
|
||||
{
|
||||
if (deformArray.Count > 0) vertices = deformArray.Items;
|
||||
Bone bone = slot.bone;
|
||||
float x = bone.worldX, y = bone.worldY;
|
||||
float a = bone.a, b = bone.b, c = bone.c, d = bone.d;
|
||||
if (deformArray.size() > 0)
|
||||
{
|
||||
vertices = deformArray;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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 + 1] = vx * c + vy * d + y;
|
||||
}
|
||||
@ -74,8 +83,8 @@ namespace Spine
|
||||
skip += n;
|
||||
}
|
||||
|
||||
var skeletonBones = skeleton.bones.Items;
|
||||
if (deformArray.Count == 0)
|
||||
Vector<Bone*>& skeletonBones = skeleton.getBones();
|
||||
if (deformArray.size() == 0)
|
||||
{
|
||||
for (int w = offset, b = skip * 3; w < count; w += stride)
|
||||
{
|
||||
@ -84,10 +93,13 @@ namespace Spine
|
||||
n += v;
|
||||
for (; v < n; v++, b += 3)
|
||||
{
|
||||
Bone bone = skeletonBones[bones[v]];
|
||||
float vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2];
|
||||
wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
|
||||
wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
|
||||
Bone* boneP = skeletonBones[bones[v]];
|
||||
Bone bone = *boneP;
|
||||
float vx = vertices[b];
|
||||
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 + 1] = wy;
|
||||
@ -95,7 +107,6 @@ namespace Spine
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector<float> deform = deformArray.Items;
|
||||
for (int w = offset, b = skip * 3, f = skip << 1; w < count; w += stride)
|
||||
{
|
||||
float wx = 0, wy = 0;
|
||||
@ -103,10 +114,13 @@ namespace Spine
|
||||
n += v;
|
||||
for (; v < n; v++, b += 3, f += 2)
|
||||
{
|
||||
Bone bone = skeletonBones[bones[v]];
|
||||
float vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2];
|
||||
wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
|
||||
wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
|
||||
Bone* boneP = skeletonBones[bones[v]];
|
||||
Bone bone = *boneP;
|
||||
float vx = vertices[b] + deformArray[f];
|
||||
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 + 1] = wy;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user