wip, these timeline classes are all pretty much the same, so this is going pretty quickly.

This commit is contained in:
Stephen Gowen 2017-11-25 14:04:49 -05:00
parent 24a3811049
commit 5411125c93
30 changed files with 471 additions and 301 deletions

View File

@ -35,155 +35,36 @@
namespace Spine
{
class DeformTimeline : CurveTimeline
class VertexAttachment;
class DeformTimeline : public CurveTimeline
{
SPINE_RTTI_DECL;
public:
DeformTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction);
virtual int getPropertyId();
// internal int slotIndex;
// internal float[] frames;
// internal float[][] frameVertices;
// internal VertexAttachment attachment;
//
// public int SlotIndex { return slotIndex; } set { slotIndex = inValue; }
// public float[] Frames { return frames; } set { frames = inValue; } // time, ...
// public float[][] Vertices { return frameVertices; } set { frameVertices = inValue; }
// public VertexAttachment Attachment { return attachment; } set { attachment = inValue; }
//
// override public int PropertyId {
// get { return ((int)TimelineType.Deform << 24) + attachment.id + slotIndex; }
// }
//
// public DeformTimeline (int frameCount)
// : base(frameCount) {
// frames = new float[frameCount];
// frameVertices = new float[frameCount][];
// }
//
// /// Sets the time and value of the specified keyframe.
// public void SetFrame (int frameIndex, float time, float[] vertices) {
// frames[frameIndex] = time;
// frameVertices[frameIndex] = vertices;
// }
//
// override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
// Slot slot = skeleton.slots.Items[slotIndex];
// VertexAttachment vertexAttachment = slot.attachment as VertexAttachment;
// if (vertexAttachment == NULL || !vertexAttachment.ApplyDeform(attachment)) return;
//
// var verticesArray = slot.attachmentVertices;
// if (verticesArray.Count == 0) alpha = 1;
//
// float[][] frameVertices = _frameVertices;
// int vertexCount = frameVertices[0].Length;
// float[] frames = _frames;
// float[] vertices;
//
// if (time < frames[0]) {
//
// switch (pose) {
// case MixPose_Setup:
// verticesArray.Clear();
// return;
// case MixPose_Current:
// if (alpha == 1) {
// verticesArray.Clear();
// return;
// }
//
// // verticesArray.SetSize(vertexCount) // Ensure size and preemptively set count.
// if (verticesArray.Capacity < vertexCount) verticesArray.Capacity = vertexCount;
// verticesArray.Count = vertexCount;
// vertices = verticesArray.Items;
//
// if (vertexAttachment.bones == NULL) {
// // Unweighted vertex positions.
// float[] setupVertices = vertexAttachment.vertices;
// for (int i = 0; i < vertexCount; i++)
// vertices[i] += (setupVertices[i] - vertices[i]) * alpha;
// } else {
// // Weighted deform offsets.
// alpha = 1 - alpha;
// for (int i = 0; i < vertexCount; i++)
// vertices[i] *= alpha;
// }
// return;
// default:
// return;
// }
//
// }
//
// // verticesArray.SetSize(vertexCount) // Ensure size and preemptively set count.
// if (verticesArray.Capacity < vertexCount) verticesArray.Capacity = vertexCount;
// verticesArray.Count = vertexCount;
// vertices = verticesArray.Items;
//
// if (time >= frames[frames.Length - 1]) { // Time is after last frame.
// float[] lastVertices = frameVertices[frames.Length - 1];
// if (alpha == 1) {
// // Vertex positions or deform offsets, no alpha.
// Array.Copy(lastVertices, 0, vertices, 0, vertexCount);
// } else if (pose == MixPose_Setup) {
// if (vertexAttachment.bones == NULL) {
// // Unweighted vertex positions, with alpha.
// float[] setupVertices = vertexAttachment.vertices;
// for (int i = 0; i < vertexCount; i++) {
// float setup = setupVertices[i];
// vertices[i] = setup + (lastVertices[i] - setup) * alpha;
// }
// } else {
// // Weighted deform offsets, with alpha.
// for (int i = 0; i < vertexCount; i++)
// vertices[i] = lastVertices[i] * alpha;
// }
// } else {
// // Vertex positions or deform offsets, with alpha.
// for (int i = 0; i < vertexCount; i++)
// vertices[i] += (lastVertices[i] - vertices[i]) * alpha;
// }
// return;
// }
//
// // Interpolate between the previous frame and the current frame.
// int frame = Animation::binarySearch(frames, time);
// float[] prevVertices = frameVertices[frame - 1];
// float[] nextVertices = frameVertices[frame];
// float frameTime = frames[frame];
// float percent = GetCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));
//
// if (alpha == 1) {
// // Vertex positions or deform offsets, no alpha.
// for (int i = 0; i < vertexCount; i++) {
// float prev = prevVertices[i];
// vertices[i] = prev + (nextVertices[i] - prev) * percent;
// }
// } else if (pose == MixPose_Setup) {
// if (vertexAttachment.bones == NULL) {
// // Unweighted vertex positions, with alpha.
// var setupVertices = vertexAttachment.vertices;
// for (int i = 0; i < vertexCount; i++) {
// float prev = prevVertices[i], setup = setupVertices[i];
// vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
// }
// } else {
// // Weighted deform offsets, with alpha.
// for (int i = 0; i < vertexCount; i++) {
// float prev = prevVertices[i];
// vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
// }
// }
// } else {
// // Vertex positions or deform offsets, with alpha.
// for (int i = 0; i < vertexCount; i++) {
// float prev = prevVertices[i];
// vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha;
// }
// }
// }
/// 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();
void setFrames(Vector<float>& inValue); // time, ...
Vector< Vector<float> >& getVertices();
void setVertices(Vector< Vector<float> >& inValue);
VertexAttachment* getAttachment();
void setAttachment(VertexAttachment* inValue);
private:
int _slotIndex;
Vector<float> _frames;
Vector< Vector<float> > _frameVertices;
VertexAttachment* _attachment;
};
}

View File

@ -38,66 +38,27 @@ namespace Spine
class DrawOrderTimeline : public Timeline
{
SPINE_RTTI_DECL;
public:
DrawOrderTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction);
virtual int getPropertyId();
// internal float[] frames;
// private int[][] drawOrders;
//
// public float[] Frames { return frames; } set { frames = inValue; } // time, ...
// public int[][] DrawOrders { return drawOrders; } set { drawOrders = inValue; }
// public int FrameCount { return frames.Length; }
//
// public int PropertyId {
// get { return ((int)TimelineType.DrawOrder << 24); }
// }
//
// public DrawOrderTimeline (int frameCount) {
// frames = new float[frameCount];
// drawOrders = new int[frameCount][];
// }
//
// /// Sets the time and value of the specified keyframe.
// /// <param name="drawOrder">May be NULL to use bind pose draw order.</param>
// public void SetFrame (int frameIndex, float time, int[] drawOrder) {
// frames[frameIndex] = time;
// drawOrders[frameIndex] = drawOrder;
// }
//
// public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
// Vector<Slot> drawOrder = skeleton.drawOrder;
// Vector<Slot> slots = skeleton.slots;
// if (direction == MixDirection_Out && pose == MixPose_Setup) {
// Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count);
// return;
// }
//
// float[] frames = _frames;
// if (time < frames[0]) {
// if (pose == MixPose_Setup) Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count);
// return;
// }
//
// int frame;
// if (time >= frames[frames.Length - 1]) // Time is after last frame.
// frame = frames.Length - 1;
// else
// frame = Animation::binarySearch(frames, time) - 1;
//
// int[] drawOrderToSetupIndex = drawOrders[frame];
// if (drawOrderToSetupIndex == NULL) {
// drawOrder.Clear();
// for (int i = 0, n = slots.Count; i < n; i++)
// drawOrder.Add(slots.Items[i]);
// } else {
// var drawOrderItems = drawOrder.Items;
// var slotsItems = slots.Items;
// for (int i = 0, n = drawOrderToSetupIndex.Length; i < n; i++)
// drawOrderItems[i] = slotsItems[drawOrderToSetupIndex[i]];
// }
// }
/// Sets the time and value of the specified keyframe.
/// @param drawOrder May be NULL to use bind pose draw order
void setFrame(int frameIndex, float time, Vector<int>& drawOrder);
Vector<float>& getFrames();
void setFrames(Vector<float>& inValue); // time, ...
Vector< Vector<int> >& getDrawOrders();
void setDrawOrders(Vector< Vector<int> >& inValue);
int getFrameCount();
private:
Vector<float> _frames;
Vector< Vector<int> > _drawOrders;
};
}

View File

@ -49,10 +49,7 @@ namespace Spine
// public float[] Frames { return frames; } set { frames = inValue; } // time, ...
// public Event[] Events { return events; } set { events = inValue; }
// public int FrameCount { return frames.Length; }
//
// public int PropertyId {
// get { return ((int)TimelineType.Event << 24); }
// }
//
//
// public EventTimeline (int frameCount) {
// frames = new float[frameCount];
@ -60,7 +57,7 @@ namespace Spine
// }
//
// /// Sets the time and value of the specified keyframe.
// public void SetFrame (int frameIndex, Event e) {
// public void setFrame (int frameIndex, Event e) {
// frames[frameIndex] = e.Time;
// events[frameIndex] = e;
// }

View File

@ -39,31 +39,29 @@ namespace Spine
{
SPINE_RTTI_DECL;
public:
static const int ENTRIES;
IkConstraintTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction);
virtual int getPropertyId();
// public const int ENTRIES = 3;
// private const int PREV_TIME = -3, PREV_MIX = -2, PREV_BEND_DIRECTION = -1;
// private const int MIX = 1, BEND_DIRECTION = 2;
//
// internal int ikConstraintIndex;
// internal float[] frames;
//
private:
static const int PREV_TIME, PREV_MIX, PREV_BEND_DIRECTION;
static const int MIX, BEND_DIRECTION;
Vector<float> _frames;
int _ikConstraintIndex;
// public int IkConstraintIndex { return ikConstraintIndex; } set { ikConstraintIndex = inValue; }
// public float[] Frames { return frames; } set { frames = inValue; } // time, mix, bendDirection, ...
//
// override public int PropertyId {
// get { return ((int)TimelineType.IkConstraint << 24) + ikConstraintIndex; }
// }
//
// public IkConstraintTimeline (int frameCount)
// : base(frameCount) {
// frames = new float[frameCount * ENTRIES];
// }
//
//
//
// /// Sets the time, mix and bend direction of the specified keyframe.
// public void SetFrame (int frameIndex, float time, float mix, int bendDirection) {
// public void setFrame (int frameIndex, float time, float mix, int bendDirection) {
// frameIndex *= ENTRIES;
// frames[frameIndex] = time;
// frames[frameIndex + MIX] = mix;

View File

@ -39,23 +39,23 @@ namespace Spine
{
SPINE_RTTI_DECL;
public:
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction);
virtual int getPropertyId();
private:
int _pathConstraintIndex;
// public const int ENTRIES = 3;
// private const int PREV_TIME = -3, PREV_ROTATE = -2, PREV_TRANSLATE = -1;
// private const int ROTATE = 1, TRANSLATE = 2;
//
// internal int pathConstraintIndex;
//
// internal float[] frames;
//
// public int PathConstraintIndex { return pathConstraintIndex; } set { pathConstraintIndex = inValue; }
// public float[] Frames { return frames; } set { frames = inValue; } // time, rotate mix, translate mix, ...
//
// override public int PropertyId {
// get { return ((int)TimelineType.PathConstraintMix << 24) + pathConstraintIndex; }
// }
//
//
// public PathConstraintMixTimeline (int frameCount)
// : base(frameCount) {
@ -63,7 +63,7 @@ namespace Spine
// }
//
// /// Sets the time and mixes of the specified keyframe.
// public void SetFrame (int frameIndex, float time, float rotateMix, float translateMix) {
// public void setFrame (int frameIndex, float time, float rotateMix, float translateMix) {
// frameIndex *= ENTRIES;
// frames[frameIndex] = time;
// frames[frameIndex + ROTATE] = rotateMix;

View File

@ -39,31 +39,32 @@ namespace Spine
{
SPINE_RTTI_DECL;
public:
static const int ENTRIES;
PathConstraintPositionTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction);
virtual int getPropertyId();
// public const int ENTRIES = 2;
// protected const int PREV_TIME = -2, PREV_VALUE = -1;
// protected const int VALUE = 1;
//
// internal int pathConstraintIndex;
// internal float[] frames;
//
// override public int PropertyId {
// get { return ((int)TimelineType.PathConstraintPosition << 24) + pathConstraintIndex; }
// }
//
// public PathConstraintPositionTimeline (int frameCount)
// : base(frameCount) {
// frames = new float[frameCount * ENTRIES];
// }
protected:
static const int PREV_TIME, PREV_VALUE;
static const int VALUE;
Vector<float> _frames;
int _pathConstraintIndex;
//
//
//
//
// public int PathConstraintIndex { return pathConstraintIndex; } set { pathConstraintIndex = inValue; }
// public float[] Frames { return frames; } set { frames = inValue; } // time, position, ...
//
// /// Sets the time and value of the specified keyframe.
// public void SetFrame (int frameIndex, float time, float value) {
// public void setFrame (int frameIndex, float time, float value) {
// frameIndex *= ENTRIES;
// frames[frameIndex] = time;
// frames[frameIndex + VALUE] = inValue;

View File

@ -39,18 +39,13 @@ namespace Spine
{
SPINE_RTTI_DECL;
public:
PathConstraintSpacingTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction);
virtual int getPropertyId();
// override public int PropertyId {
// get { return ((int)TimelineType.PathConstraintSpacing << 24) + pathConstraintIndex; }
// }
//
// public PathConstraintSpacingTimeline (int frameCount)
// : base(frameCount) {
// }
//
// override public void Apply (Skeleton skeleton, float lastTime, float time, Vector<Event> firedEvents, float alpha, MixPose pose, MixDirection direction) {
// PathConstraint constraint = skeleton.pathConstraints.Items[pathConstraintIndex];
// float[] frames = _frames;

View File

@ -43,10 +43,6 @@ namespace Spine
virtual int getPropertyId();
// override public int PropertyId {
// get { return ((int)TimelineType.Scale << 24) + boneIndex; }
// }
//
// public ScaleTimeline (int frameCount)
// : base(frameCount) {
// }

View File

@ -39,14 +39,11 @@ namespace Spine
{
SPINE_RTTI_DECL;
public:
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction);
virtual int getPropertyId();
// override public int PropertyId {
// get { return ((int)TimelineType.Shear << 24) + boneIndex; }
// }
//
// public ShearTimeline (int frameCount)
// : base(frameCount) {
// }

View File

@ -61,15 +61,15 @@ namespace Spine
#define SPINE_RTTI_DECL \
public: \
static const Spine::SPINE_RTTI rtti; \
virtual const Spine::SPINE_RTTI& getSPINE_RTTI();
virtual const Spine::SPINE_RTTI& getRTTI();
#define SPINE_RTTI_IMPL_NOPARENT(name) \
const Spine::SPINE_RTTI name::rtti(#name); \
const Spine::SPINE_RTTI& name::getSPINE_RTTI() { return rtti; }
const Spine::SPINE_RTTI& name::getRTTI() { return rtti; }
#define SPINE_RTTI_IMPL(name,parent) \
const Spine::SPINE_RTTI name::rtti(#name, parent::rtti); \
const Spine::SPINE_RTTI& name::getSPINE_RTTI() { return rtti; }
const Spine::SPINE_RTTI& name::getRTTI() { return rtti; }
#endif /* Spine_SPINE_RTTI_h */

View File

@ -39,30 +39,31 @@ namespace Spine
{
SPINE_RTTI_DECL;
public:
static const int ENTRIES;
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction);
virtual int getPropertyId();
// public const int ENTRIES = 5;
// private const int PREV_TIME = -5, PREV_ROTATE = -4, PREV_TRANSLATE = -3, PREV_SCALE = -2, PREV_SHEAR = -1;
// private const int ROTATE = 1, TRANSLATE = 2, SCALE = 3, SHEAR = 4;
//
// internal int transformConstraintIndex;
private:
static const int PREV_TIME, PREV_ROTATE, PREV_TRANSLATE, PREV_SCALE, PREV_SHEAR;
static const int ROTATE, TRANSLATE, SCALE, SHEAR;
int _transformConstraintIndex;
// internal float[] frames;
//
// public int TransformConstraintIndex { return transformConstraintIndex; } set { transformConstraintIndex = inValue; }
// public float[] Frames { return frames; } set { frames = inValue; } // time, rotate mix, translate mix, scale mix, shear mix, ...
//
// override public int PropertyId {
// get { return ((int)TimelineType.TransformConstraint << 24) + transformConstraintIndex; }
// }
//
// public TransformConstraintTimeline (int frameCount)
// : base(frameCount) {
// frames = new float[frameCount * ENTRIES];
// }
//
// public void SetFrame (int frameIndex, float time, float rotateMix, float translateMix, float scaleMix, float shearMix) {
// public void setFrame (int frameIndex, float time, float rotateMix, float translateMix, float scaleMix, float shearMix) {
// frameIndex *= ENTRIES;
// frames[frameIndex] = time;
// frames[frameIndex + ROTATE] = rotateMix;

View File

@ -42,24 +42,23 @@ namespace Spine
{
SPINE_RTTI_DECL;
public:
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction);
virtual int getPropertyId();
protected:
int _boneIndex;
// public const int ENTRIES = 3;
// protected const int PREV_TIME = -3, PREV_X = -2, PREV_Y = -1;
// protected const int X = 1, Y = 2;
//
// internal int boneIndex;
// internal float[] frames;
//
// public int getBoneIndex { return boneIndex; } set { boneIndex = inValue; }
// public Vector<float> getFrames { return frames; } set { frames = inValue; } // time, value, value, ...
//
// virtual int getPropertyId()
// {
// return ((int)TimelineType_Translate << 24) + boneIndex;
// }
//
// public TranslateTimeline(int frameCount) : CurveTimeline(frameCount)
// {

View File

@ -39,10 +39,14 @@ namespace Spine
{
SPINE_RTTI_DECL;
public:
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction);
virtual int getPropertyId();
private:
int _slotIndex;
// public const int ENTRIES = 8;
// protected const int PREV_TIME = -8, PREV_R = -7, PREV_G = -6, PREV_B = -5, PREV_A = -4;
// protected const int PREV_R2 = -3, PREV_G2 = -2, PREV_B2 = -1;
@ -51,7 +55,6 @@ namespace Spine
// internal float[] frames; // time, r, g, b, a, r2, g2, b2, ...
// public float[] Frames { return frames; }
//
// internal int slotIndex;
// public int SlotIndex {
// get { return slotIndex; }
// set {
@ -60,9 +63,6 @@ namespace Spine
// }
// }
//
// override public int PropertyId {
// get { return ((int)TimelineType.TwoColor << 24) + slotIndex; }
// }
//
// public TwoColorTimeline (int frameCount) :
// base(frameCount) {
@ -70,7 +70,7 @@ namespace Spine
// }
//
// /// Sets the time and value of the specified keyframe.
// public void SetFrame (int frameIndex, float time, float r, float g, float b, float a, float r2, float g2, float b2) {
// public void setFrame (int frameIndex, float time, float r, float g, float b, float a, float r2, float g2, float b2) {
// frameIndex *= ENTRIES;
// frames[frameIndex] = time;
// frames[frameIndex + R] = r;

View File

@ -44,6 +44,8 @@ namespace Spine
{
SPINE_RTTI_DECL;
friend class DeformTimeline;
public:
VertexAttachment(std::string name);

View File

@ -42,7 +42,7 @@ namespace Spine
{
SPINE_RTTI_IMPL(AttachmentTimeline, Timeline);
AttachmentTimeline::AttachmentTimeline(int frameCount)
AttachmentTimeline::AttachmentTimeline(int frameCount) : Timeline(), _slotIndex(0)
{
_frames.reserve(frameCount);
_attachmentNames.reserve(frameCount);

View File

@ -53,7 +53,7 @@ namespace Spine
const int ColorTimeline::B = 3;
const int ColorTimeline::A = 4;
ColorTimeline::ColorTimeline(int frameCount) : CurveTimeline(frameCount)
ColorTimeline::ColorTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0)
{
_frames.reserve(frameCount * ENTRIES);
}

View File

@ -33,6 +33,8 @@
#include <spine/Skeleton.h>
#include <spine/Event.h>
#include <spine/VertexAttachment.h>
#include <spine/Animation.h>
#include <spine/TimelineType.h>
#include <spine/Slot.h>
@ -42,13 +44,225 @@ namespace Spine
{
SPINE_RTTI_IMPL(DeformTimeline, CurveTimeline);
DeformTimeline::DeformTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0), _attachment(NULL)
{
_frames.reserve(frameCount);
_frameVertices.reserve(frameCount);
}
void DeformTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction)
{
// TODO
Slot* slotP = skeleton._slots[_slotIndex];
Slot& slot = *slotP;
if (slot._attachment == NULL || !slot._attachment->getRTTI().derivesFrom(VertexAttachment::rtti))
{
return;
}
VertexAttachment* vertexAttachment = static_cast<VertexAttachment*>(slot._attachment);
if (!vertexAttachment->applyDeform(_attachment))
{
return;
}
Vector<float>& vertices = slot._attachmentVertices;
if (vertices.size() == 0)
{
alpha = 1;
}
int vertexCount = static_cast<int>(_frameVertices[0].size());
if (time < _frames[0])
{
switch (pose)
{
case MixPose_Setup:
vertices.clear();
return;
case MixPose_Current:
if (alpha == 1)
{
vertices.clear();
return;
}
// Ensure size and preemptively set count.
vertices.reserve(vertexCount);
if (vertexAttachment->_bones.size() == 0)
{
// Unweighted vertex positions.
Vector<float>& setupVertices = vertexAttachment->_vertices;
for (int i = 0; i < vertexCount; ++i)
{
vertices[i] += (setupVertices[i] - vertices[i]) * alpha;
}
}
else
{
// Weighted deform offsets.
alpha = 1 - alpha;
for (int i = 0; i < vertexCount; ++i)
{
vertices[i] *= alpha;
}
}
return;
default:
return;
}
}
// Ensure size and preemptively set count.
vertices.reserve(vertexCount);
if (time >= _frames[_frames.size() - 1])
{
// Time is after last frame.
Vector<float>& lastVertices = _frameVertices[_frames.size() - 1];
if (alpha == 1)
{
// Vertex positions or deform offsets, no alpha.
vertices.clear();
for (int i = 0; i < vertexCount; ++i)
{
float vertex = lastVertices[i];
vertices.push_back(vertex);
}
}
else if (pose == MixPose_Setup)
{
if (vertexAttachment->_bones.size() == 0)
{
// Unweighted vertex positions, with alpha.
Vector<float>& setupVertices = vertexAttachment->_vertices;
for (int i = 0; i < vertexCount; i++)
{
float setup = setupVertices[i];
vertices[i] = setup + (lastVertices[i] - setup) * alpha;
}
}
else
{
// Weighted deform offsets, with alpha.
for (int i = 0; i < vertexCount; ++i)
{
vertices[i] = lastVertices[i] * alpha;
}
}
}
else
{
// Vertex positions or deform offsets, with alpha.
for (int i = 0; i < vertexCount; ++i)
{
vertices[i] += (lastVertices[i] - vertices[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)
{
// Vertex positions or deform offsets, no alpha.
for (int i = 0; i < vertexCount; ++i)
{
float prev = prevVertices[i];
vertices[i] = prev + (nextVertices[i] - prev) * percent;
}
}
else if (pose == MixPose_Setup)
{
if (vertexAttachment->_bones.size() == 0)
{
// Unweighted vertex positions, with alpha.
Vector<float>& setupVertices = vertexAttachment->_vertices;
for (int i = 0; i < vertexCount; ++i)
{
float prev = prevVertices[i], setup = setupVertices[i];
vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
}
}
else
{
// Weighted deform offsets, with alpha.
for (int i = 0; i < vertexCount; ++i)
{
float prev = prevVertices[i];
vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
}
}
}
else
{
// Vertex positions or deform offsets, with alpha.
for (int i = 0; i < vertexCount; ++i)
{
float prev = prevVertices[i];
vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha;
}
}
}
int DeformTimeline::getPropertyId()
{
return 0;
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] = vertices;
}
int DeformTimeline::getSlotIndex()
{
return _slotIndex;
}
void DeformTimeline::setSlotIndex(int inValue)
{
_slotIndex = inValue;
}
Vector<float>& DeformTimeline::getFrames()
{
return _frames;
}
void DeformTimeline::setFrames(Vector<float>& inValue)
{
_frames = inValue;
}
Vector< Vector<float> >& DeformTimeline::getVertices()
{
return _frameVertices;
}
void DeformTimeline::setVertices(Vector< Vector<float> >& inValue)
{
_frameVertices = inValue;
}
VertexAttachment* DeformTimeline::getAttachment()
{
return _attachment;
}
void DeformTimeline::setAttachment(VertexAttachment* inValue)
{
_attachment = inValue;
}
}

View File

@ -42,13 +42,103 @@ namespace Spine
{
SPINE_RTTI_IMPL(DrawOrderTimeline, Timeline);
DrawOrderTimeline::DrawOrderTimeline(int frameCount) : Timeline()
{
_frames.reserve(frameCount);
_drawOrders.reserve(frameCount);
}
void DrawOrderTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction)
{
// TODO
Vector<Slot*>& drawOrder = skeleton._drawOrder;
Vector<Slot*>& slots = skeleton._slots;
if (direction == MixDirection_Out && pose == MixPose_Setup)
{
drawOrder.clear();
drawOrder.reserve(slots.size());
for (int i = 0, n = static_cast<int>(slots.size()); i < n; ++i)
{
drawOrder.push_back(slots[i]);
}
return;
}
if (time < _frames[0])
{
if (pose == MixPose_Setup)
{
drawOrder.clear();
drawOrder.reserve(slots.size());
for (int i = 0, n = static_cast<int>(slots.size()); i < n; ++i)
{
drawOrder.push_back(slots[i]);
}
}
return;
}
int frame;
if (time >= _frames[_frames.size() - 1])
{
// Time is after last frame.
frame = static_cast<int>(_frames.size()) - 1;
}
else
{
frame = Animation::binarySearch(_frames, time) - 1;
}
Vector<int>& drawOrderToSetupIndex = _drawOrders[frame];
if (drawOrderToSetupIndex.size() == 0)
{
drawOrder.clear();
for (int i = 0, n = static_cast<int>(slots.size()); i < n; ++i)
{
drawOrder.push_back(slots[i]);
}
}
else
{
for (int i = 0, n = static_cast<int>(drawOrderToSetupIndex.size()); i < n; ++i)
{
drawOrder[i] = slots[drawOrderToSetupIndex[i]];
}
}
}
int DrawOrderTimeline::getPropertyId()
{
return 0;
return ((int)TimelineType_DrawOrder << 24);
}
void DrawOrderTimeline::setFrame(int frameIndex, float time, Vector<int>& drawOrder)
{
_frames[frameIndex] = time;
_drawOrders[frameIndex] = drawOrder;
}
Vector<float>& DrawOrderTimeline::getFrames()
{
return _frames;
}
void DrawOrderTimeline::setFrames(Vector<float>& inValue)
{
_frames = inValue;
}
Vector< Vector<int> >& DrawOrderTimeline::getDrawOrders()
{
return _drawOrders;
}
void DrawOrderTimeline::setDrawOrders(Vector< Vector<int> >& inValue)
{
_drawOrders = inValue;
}
int DrawOrderTimeline::getFrameCount()
{
return static_cast<int>(_frames.size());
}
}

View File

@ -49,6 +49,6 @@ namespace Spine
int EventTimeline::getPropertyId()
{
return 0;
return ((int)TimelineType_Event << 24);
}
}

View File

@ -42,6 +42,18 @@ namespace Spine
{
SPINE_RTTI_IMPL(IkConstraintTimeline, CurveTimeline);
const int IkConstraintTimeline::ENTRIES = 3;
const int IkConstraintTimeline::PREV_TIME = -3;
const int IkConstraintTimeline::PREV_MIX = -2;
const int IkConstraintTimeline::PREV_BEND_DIRECTION = -1;
const int IkConstraintTimeline::MIX = 1;
const int IkConstraintTimeline::BEND_DIRECTION = 2;
IkConstraintTimeline::IkConstraintTimeline(int frameCount) : CurveTimeline(frameCount), _ikConstraintIndex(0)
{
_frames.reserve(frameCount * ENTRIES);
}
void IkConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction)
{
// TODO
@ -49,6 +61,6 @@ namespace Spine
int IkConstraintTimeline::getPropertyId()
{
return 0;
return ((int)TimelineType_IkConstraint << 24) + _ikConstraintIndex;
}
}

View File

@ -79,7 +79,7 @@ namespace Spine
void PathConstraint::update()
{
Attachment* baseAttachment = _target->getAttachment();
if (baseAttachment == NULL || !baseAttachment->getSPINE_RTTI().derivesFrom(PathAttachment::rtti))
if (baseAttachment == NULL || !baseAttachment->getRTTI().derivesFrom(PathAttachment::rtti))
{
return;
}

View File

@ -49,6 +49,6 @@ namespace Spine
int PathConstraintMixTimeline::getPropertyId()
{
return 0;
return ((int)TimelineType_PathConstraintMix << 24) + _pathConstraintIndex;
}
}

View File

@ -42,6 +42,16 @@ namespace Spine
{
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)
{
_frames.reserve(frameCount * ENTRIES);
}
void PathConstraintPositionTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction)
{
// TODO
@ -49,6 +59,6 @@ namespace Spine
int PathConstraintPositionTimeline::getPropertyId()
{
return 0;
return ((int)TimelineType_PathConstraintPosition << 24) + _pathConstraintIndex;
}
}

View File

@ -42,6 +42,11 @@ namespace Spine
{
SPINE_RTTI_IMPL(PathConstraintSpacingTimeline, PathConstraintPositionTimeline);
PathConstraintSpacingTimeline::PathConstraintSpacingTimeline(int frameCount) : PathConstraintPositionTimeline(frameCount)
{
// Empty
}
void PathConstraintSpacingTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction)
{
// TODO
@ -49,6 +54,6 @@ namespace Spine
int PathConstraintSpacingTimeline::getPropertyId()
{
return 0;
return ((int)TimelineType_PathConstraintSpacing << 24) + _pathConstraintIndex;
}
}

View File

@ -49,6 +49,6 @@ namespace Spine
int ScaleTimeline::getPropertyId()
{
return 0;
return ((int)TimelineType_Scale << 24) + _boneIndex;
}
}

View File

@ -49,6 +49,6 @@ namespace Spine
int ShearTimeline::getPropertyId()
{
return 0;
return ((int)TimelineType_Shear << 24) + _boneIndex;
}
}

View File

@ -484,7 +484,7 @@ namespace Spine
int verticesLength = 0;
Attachment* attachment = slot->getAttachment();
if (attachment != NULL && attachment->getSPINE_RTTI().derivesFrom(RegionAttachment::rtti))
if (attachment != NULL && attachment->getRTTI().derivesFrom(RegionAttachment::rtti))
{
RegionAttachment* regionAttachment = static_cast<RegionAttachment*>(attachment);
@ -495,7 +495,7 @@ namespace Spine
}
regionAttachment->computeWorldVertices(slot->getBone(), outVertexBuffer, 0);
}
else if (attachment != NULL && attachment->getSPINE_RTTI().derivesFrom(MeshAttachment::rtti))
else if (attachment != NULL && attachment->getRTTI().derivesFrom(MeshAttachment::rtti))
{
MeshAttachment* mesh = static_cast<MeshAttachment*>(attachment);
@ -712,7 +712,7 @@ namespace Spine
}
Attachment* attachment = slot->_attachment;
if (attachment != NULL && attachment->getSPINE_RTTI().derivesFrom(PathAttachment::rtti))
if (attachment != NULL && attachment->getRTTI().derivesFrom(PathAttachment::rtti))
{
sortPathConstraintAttachment(attachment, slotBone);
}
@ -793,7 +793,7 @@ namespace Spine
void Skeleton::sortPathConstraintAttachment(Attachment* attachment, Bone& slotBone)
{
if (attachment == NULL || attachment->getSPINE_RTTI().derivesFrom(PathAttachment::rtti))
if (attachment == NULL || attachment->getRTTI().derivesFrom(PathAttachment::rtti))
{
return;
}

View File

@ -42,6 +42,17 @@ namespace Spine
{
SPINE_RTTI_IMPL(TransformConstraintTimeline, CurveTimeline);
const int TransformConstraintTimeline::ENTRIES = 5;
const int TransformConstraintTimeline::PREV_TIME = -5;
const int TransformConstraintTimeline::PREV_ROTATE = -4;
const int TransformConstraintTimeline::PREV_TRANSLATE = -3;
const int TransformConstraintTimeline::PREV_SCALE = -2;
const int TransformConstraintTimeline::PREV_SHEAR = -1;
const int TransformConstraintTimeline::ROTATE = 1;
const int TransformConstraintTimeline::TRANSLATE = 2;
const int TransformConstraintTimeline::SCALE = 3;
const int TransformConstraintTimeline::SHEAR = 4;
void TransformConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>& events, float alpha, MixPose pose, MixDirection direction)
{
// TODO
@ -49,6 +60,6 @@ namespace Spine
int TransformConstraintTimeline::getPropertyId()
{
return 0;
return ((int)TimelineType_TransformConstraint << 24) + _transformConstraintIndex;
}
}

View File

@ -49,6 +49,6 @@ namespace Spine
int TranslateTimeline::getPropertyId()
{
return 0;
return ((int)TimelineType_Translate << 24) + _boneIndex;
}
}

View File

@ -49,6 +49,6 @@ namespace Spine
int TwoColorTimeline::getPropertyId()
{
return 0;
return ((int)TimelineType_TwoColor << 24) + _slotIndex;
}
}