mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-05 02:06:53 +08:00
[cpp] 4.3 porting WIP
This commit is contained in:
parent
205b390195
commit
e5c9f9b86a
@ -55,7 +55,7 @@ namespace spine {
|
|||||||
|
|
||||||
using VertexAttachment::computeWorldVertices;
|
using VertexAttachment::computeWorldVertices;
|
||||||
|
|
||||||
virtual void computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset,
|
virtual void computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset,
|
||||||
size_t stride = 2);
|
size_t stride = 2);
|
||||||
|
|
||||||
void updateRegion();
|
void updateRegion();
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
class Bone;
|
class Bone;
|
||||||
|
class BonePose;
|
||||||
|
|
||||||
/// An attachment which is a single point and a rotation. This can be used to spawn projectiles, particles, etc. A bone can be
|
/// 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
|
/// used in similar ways, but a PointAttachment is slightly less expensive to compute and can be hidden, shown, and placed in a
|
||||||
@ -66,9 +67,9 @@ namespace spine {
|
|||||||
|
|
||||||
Color &getColor();
|
Color &getColor();
|
||||||
|
|
||||||
void computeWorldPosition(Bone &bone, float &ox, float &oy);
|
void computeWorldPosition(BonePose &bone, float &ox, float &oy);
|
||||||
|
|
||||||
float computeWorldRotation(Bone &bone);
|
float computeWorldRotation(BonePose &bone);
|
||||||
|
|
||||||
virtual Attachment *copy();
|
virtual Attachment *copy();
|
||||||
|
|
||||||
|
|||||||
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
class Slot;
|
class Slot;
|
||||||
|
class Skeleton;
|
||||||
|
|
||||||
/// An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's vertices.
|
/// An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's vertices.
|
||||||
class SP_API VertexAttachment : public Attachment {
|
class SP_API VertexAttachment : public Attachment {
|
||||||
@ -52,9 +53,6 @@ namespace spine {
|
|||||||
|
|
||||||
virtual ~VertexAttachment();
|
virtual ~VertexAttachment();
|
||||||
|
|
||||||
void computeWorldVertices(Slot &slot, float *worldVertices);
|
|
||||||
|
|
||||||
void computeWorldVertices(Slot &slot, Vector<float> &worldVertices);
|
|
||||||
|
|
||||||
/// Transforms local vertices to world coordinates.
|
/// Transforms local vertices to world coordinates.
|
||||||
/// @param start The index of the first Vertices value to transform. Each vertex has 2 values, x and y.
|
/// @param start The index of the first Vertices value to transform. Each vertex has 2 values, x and y.
|
||||||
@ -62,10 +60,10 @@ namespace spine {
|
|||||||
/// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + count.
|
/// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + count.
|
||||||
/// @param offset The worldVertices index to begin writing values.
|
/// @param offset The worldVertices index to begin writing values.
|
||||||
/// @param stride The number of worldVertices entries between the value pairs written.
|
/// @param stride The number of worldVertices entries between the value pairs written.
|
||||||
virtual void computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset,
|
virtual void computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset,
|
||||||
size_t stride = 2);
|
size_t stride = 2);
|
||||||
|
|
||||||
virtual void computeWorldVertices(Slot &slot, size_t start, size_t count, Vector<float> &worldVertices, size_t offset,
|
virtual void computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, Vector<float> &worldVertices, size_t offset,
|
||||||
size_t stride = 2);
|
size_t stride = 2);
|
||||||
|
|
||||||
/// Gets a unique ID for this attachment.
|
/// Gets a unique ID for this attachment.
|
||||||
|
|||||||
@ -234,8 +234,8 @@ MeshAttachment *MeshAttachment::newLinkedMesh() {
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset,
|
void MeshAttachment::computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset,
|
||||||
size_t stride) {
|
size_t stride) {
|
||||||
if (_sequence) _sequence->apply(&slot, this);
|
if (_sequence) _sequence->apply(slot.getAppliedPose(), this);
|
||||||
VertexAttachment::computeWorldVertices(slot, start, count, worldVertices, offset, stride);
|
VertexAttachment::computeWorldVertices(skeleton, slot, start, count, worldVertices, offset, stride);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,15 +68,15 @@ Color &PointAttachment::getColor() {
|
|||||||
return _color;
|
return _color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PointAttachment::computeWorldPosition(Bone &bone, float &ox, float &oy) {
|
void PointAttachment::computeWorldPosition(BonePose &bone, float &ox, float &oy) {
|
||||||
ox = _x * bone._a + _y * bone._b + bone._worldX;
|
ox = _x * bone.getA() + _y * bone.getB() + bone.getWorldX();
|
||||||
oy = _x * bone._c + _y * bone._d + bone._worldY;
|
oy = _x * bone.getC() + _y * bone.getD() + bone.getWorldY();
|
||||||
}
|
}
|
||||||
|
|
||||||
float PointAttachment::computeWorldRotation(Bone &bone) {
|
float PointAttachment::computeWorldRotation(BonePose &bone) {
|
||||||
float r = _rotation * MathUtil::Deg_Rad, cosine = MathUtil::cos(r), sine = MathUtil::sin(r);
|
float r = _rotation * MathUtil::Deg_Rad, cosine = MathUtil::cos(r), sine = MathUtil::sin(r);
|
||||||
float x = cosine * bone._a + sine * bone._b;
|
float x = cosine * bone.getA() + sine * bone.getB();
|
||||||
float y = cosine * bone._c + sine * bone._d;
|
float y = cosine * bone.getC() + sine * bone.getD();
|
||||||
return MathUtil::atan2Deg(y, x);
|
return MathUtil::atan2Deg(y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -133,9 +133,9 @@ void RegionAttachment::computeWorldVertices(Slot &slot, Vector<float> &worldVert
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RegionAttachment::computeWorldVertices(Slot &slot, float *worldVertices, size_t offset, size_t stride) {
|
void RegionAttachment::computeWorldVertices(Slot &slot, float *worldVertices, size_t offset, size_t stride) {
|
||||||
if (_sequence) _sequence->apply(&slot, this);
|
if (_sequence) _sequence->apply(slot.getAppliedPose(), this);
|
||||||
|
|
||||||
Bone &bone = slot.getBone();
|
BonePose &bone = slot.getBone().getAppliedPose();
|
||||||
float x = bone.getWorldX(), y = bone.getWorldY();
|
float x = bone.getWorldX(), y = bone.getWorldY();
|
||||||
float a = bone.getA(), b = bone.getB(), c = bone.getC(), d = bone.getD();
|
float a = bone.getA(), b = bone.getB(), c = bone.getC(), d = bone.getD();
|
||||||
float offsetX, offsetY;
|
float offsetX, offsetY;
|
||||||
|
|||||||
@ -45,33 +45,25 @@ VertexAttachment::VertexAttachment(const String &name) : Attachment(name), _worl
|
|||||||
VertexAttachment::~VertexAttachment() {
|
VertexAttachment::~VertexAttachment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexAttachment::computeWorldVertices(Slot &slot, Vector<float> &worldVertices) {
|
|
||||||
computeWorldVertices(slot, 0, _worldVerticesLength, worldVertices, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VertexAttachment::computeWorldVertices(Slot &slot, float *worldVertices) {
|
void VertexAttachment::computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, Vector<float> &worldVertices,
|
||||||
computeWorldVertices(slot, 0, _worldVerticesLength, worldVertices, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, Vector<float> &worldVertices,
|
|
||||||
size_t offset, size_t stride) {
|
size_t offset, size_t stride) {
|
||||||
computeWorldVertices(slot, start, count, worldVertices.buffer(), offset, stride);
|
computeWorldVertices(skeleton, slot, start, count, worldVertices.buffer(), offset, stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset,
|
void VertexAttachment::computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset,
|
||||||
size_t stride) {
|
size_t stride) {
|
||||||
count = offset + (count >> 1) * stride;
|
count = offset + (count >> 1) * stride;
|
||||||
Skeleton &skeleton = slot._bone._skeleton;
|
Vector<float> *deformArray = &slot.getAppliedPose().getDeform();
|
||||||
Vector<float> *deformArray = &slot.getDeform();
|
|
||||||
Vector<float> *vertices = &_vertices;
|
Vector<float> *vertices = &_vertices;
|
||||||
Vector<int> &bones = _bones;
|
Vector<int> &bones = _bones;
|
||||||
if (bones.size() == 0) {
|
if (bones.size() == 0) {
|
||||||
if (deformArray->size() > 0) vertices = deformArray;
|
if (deformArray->size() > 0) vertices = deformArray;
|
||||||
|
|
||||||
Bone &bone = slot._bone;
|
BonePose &bone = slot.getBone().getAppliedPose();
|
||||||
float x = bone._worldX;
|
float x = bone.getWorldX();
|
||||||
float y = bone._worldY;
|
float y = bone.getWorldY();
|
||||||
float a = bone._a, b = bone._b, c = bone._c, d = bone._d;
|
float a = bone.getA(), b = bone.getB(), c = bone.getC(), d = bone.getD();
|
||||||
for (size_t vv = start, w = offset; w < count; vv += 2, w += stride) {
|
for (size_t vv = start, w = offset; w < count; vv += 2, w += stride) {
|
||||||
float vx = (*vertices)[vv];
|
float vx = (*vertices)[vv];
|
||||||
float vy = (*vertices)[vv + 1];
|
float vy = (*vertices)[vv + 1];
|
||||||
@ -96,12 +88,12 @@ void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t cou
|
|||||||
n += v;
|
n += v;
|
||||||
for (; v < n; v++, b += 3) {
|
for (; v < n; v++, b += 3) {
|
||||||
Bone *boneP = skeletonBones[bones[v]];
|
Bone *boneP = skeletonBones[bones[v]];
|
||||||
Bone &bone = *boneP;
|
BonePose &bonePose = boneP->getAppliedPose();
|
||||||
float vx = (*vertices)[b];
|
float vx = (*vertices)[b];
|
||||||
float vy = (*vertices)[b + 1];
|
float vy = (*vertices)[b + 1];
|
||||||
float weight = (*vertices)[b + 2];
|
float weight = (*vertices)[b + 2];
|
||||||
wx += (vx * bone._a + vy * bone._b + bone._worldX) * weight;
|
wx += (vx * bonePose.getA() + vy * bonePose.getB() + bonePose.getWorldX()) * weight;
|
||||||
wy += (vx * bone._c + vy * bone._d + bone._worldY) * weight;
|
wy += (vx * bonePose.getC() + vy * bonePose.getD() + bonePose.getWorldY()) * weight;
|
||||||
}
|
}
|
||||||
worldVertices[w] = wx;
|
worldVertices[w] = wx;
|
||||||
worldVertices[w + 1] = wy;
|
worldVertices[w + 1] = wy;
|
||||||
@ -113,12 +105,12 @@ void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t cou
|
|||||||
n += v;
|
n += v;
|
||||||
for (; v < n; v++, b += 3, f += 2) {
|
for (; v < n; v++, b += 3, f += 2) {
|
||||||
Bone *boneP = skeletonBones[bones[v]];
|
Bone *boneP = skeletonBones[bones[v]];
|
||||||
Bone &bone = *boneP;
|
BonePose &bonePose = boneP->getAppliedPose();
|
||||||
float vx = (*vertices)[b] + (*deformArray)[f];
|
float vx = (*vertices)[b] + (*deformArray)[f];
|
||||||
float vy = (*vertices)[b + 1] + (*deformArray)[f + 1];
|
float vy = (*vertices)[b + 1] + (*deformArray)[f + 1];
|
||||||
float weight = (*vertices)[b + 2];
|
float weight = (*vertices)[b + 2];
|
||||||
wx += (vx * bone._a + vy * bone._b + bone._worldX) * weight;
|
wx += (vx * bonePose.getA() + vy * bonePose.getB() + bonePose.getWorldX()) * weight;
|
||||||
wy += (vx * bone._c + vy * bone._d + bone._worldY) * weight;
|
wy += (vx * bonePose.getC() + vy * bonePose.getD() + bonePose.getWorldY()) * weight;
|
||||||
}
|
}
|
||||||
worldVertices[w] = wx;
|
worldVertices[w] = wx;
|
||||||
worldVertices[w + 1] = wy;
|
worldVertices[w + 1] = wy;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user