mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[c] Ported DeformTimeline changes
This commit is contained in:
parent
43efcaf373
commit
3212e44aa9
@ -40,7 +40,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SP_ANIMATION_START, SP_ANIMATION_END, SP_ANIMATION_COMPLETE, SP_ANIMATION_EVENT
|
SP_ANIMATION_START, SP_ANIMATION_INTERRUPT, SP_ANIMATION_END, SP_ANIMATION_COMPLETE, SP_ANIMATION_DISPOSE, SP_ANIMATION_EVENT
|
||||||
} spEventType;
|
} spEventType;
|
||||||
|
|
||||||
typedef struct spAnimationState spAnimationState;
|
typedef struct spAnimationState spAnimationState;
|
||||||
|
|||||||
@ -796,6 +796,10 @@ void _spDeformTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton,
|
|||||||
float percent, frameTime;
|
float percent, frameTime;
|
||||||
const float* prevVertices;
|
const float* prevVertices;
|
||||||
const float* nextVertices;
|
const float* nextVertices;
|
||||||
|
float* frames;
|
||||||
|
int framesCount;
|
||||||
|
const float** frameVertices;
|
||||||
|
float* vertices;
|
||||||
spDeformTimeline* self = (spDeformTimeline*)timeline;
|
spDeformTimeline* self = (spDeformTimeline*)timeline;
|
||||||
|
|
||||||
spSlot *slot = skeleton->slots[self->slotIndex];
|
spSlot *slot = skeleton->slots[self->slotIndex];
|
||||||
@ -813,7 +817,12 @@ void _spDeformTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time < self->frames[0]) return; /* Time is before first frame. */
|
frames = self->frames;
|
||||||
|
framesCount = self->framesCount;
|
||||||
|
if (time < frames[0]) { /* Time is before first frame. */
|
||||||
|
if (setupPose) slot->attachmentVerticesCount = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
vertexCount = self->frameVerticesCount;
|
vertexCount = self->frameVerticesCount;
|
||||||
if (slot->attachmentVerticesCount < vertexCount) {
|
if (slot->attachmentVerticesCount < vertexCount) {
|
||||||
@ -826,34 +835,70 @@ void _spDeformTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton,
|
|||||||
if (slot->attachmentVerticesCount != vertexCount) alpha = 1; /* Don't mix from uninitialized slot vertices. */
|
if (slot->attachmentVerticesCount != vertexCount) alpha = 1; /* Don't mix from uninitialized slot vertices. */
|
||||||
slot->attachmentVerticesCount = vertexCount;
|
slot->attachmentVerticesCount = vertexCount;
|
||||||
|
|
||||||
if (time >= self->frames[self->framesCount - 1]) {
|
frameVertices = self->frameVertices;
|
||||||
/* Time is after last frame. */
|
vertices = slot->attachmentVertices;
|
||||||
const float* lastVertices = self->frameVertices[self->framesCount - 1];
|
|
||||||
if (alpha < 1) {
|
if (time >= frames[framesCount - 1]) { /* Time is after last frame. */
|
||||||
for (i = 0; i < vertexCount; ++i)
|
const float* lastVertices = self->frameVertices[framesCount - 1];
|
||||||
slot->attachmentVertices[i] += (lastVertices[i] - slot->attachmentVertices[i]) * alpha;
|
if (alpha == 1) {
|
||||||
} else
|
/* Vertex positions or deform offsets, no alpha. */
|
||||||
memcpy(slot->attachmentVertices, lastVertices, vertexCount * sizeof(float));
|
memcpy(vertices, lastVertices, vertexCount * sizeof(float));
|
||||||
|
} else if (setupPose) {
|
||||||
|
spVertexAttachment* vertexAttachment = SUB_CAST(spVertexAttachment, slot->attachment);
|
||||||
|
if (!vertexAttachment->bones) {
|
||||||
|
/* Unweighted vertex positions, with alpha. */
|
||||||
|
float* setupVertices = vertexAttachment->vertices;
|
||||||
|
for (i = 0; i < vertexCount; i++) {
|
||||||
|
float setup = setupVertices[i];
|
||||||
|
vertices[i] = setup + (lastVertices[i] - setup) * alpha;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Weighted deform offsets, with alpha. */
|
||||||
|
for (i = 0; i < vertexCount; i++)
|
||||||
|
vertices[i] = lastVertices[i] * alpha;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Vertex positions or deform offsets, with alpha. */
|
||||||
|
for (i = 0; i < vertexCount; i++)
|
||||||
|
vertices[i] += (lastVertices[i] - vertices[i]) * alpha;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Interpolate between the previous frame and the current frame. */
|
/* Interpolate between the previous frame and the current frame. */
|
||||||
frame = binarySearch1(self->frames, self->framesCount, time);
|
frame = binarySearch(frames, framesCount, time, 1);
|
||||||
frameTime = self->frames[frame];
|
prevVertices = frameVertices[frame - 1];
|
||||||
percent = spCurveTimeline_getCurvePercent(SUPER(self), frame - 1, 1 - (time - frameTime) / (self->frames[frame - 1] - frameTime));
|
nextVertices = frameVertices[frame];
|
||||||
|
frameTime = frames[frame];
|
||||||
|
percent = spCurveTimeline_getCurvePercent(SUPER(self), frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));
|
||||||
|
|
||||||
prevVertices = self->frameVertices[frame - 1];
|
if (alpha == 1) {
|
||||||
nextVertices = self->frameVertices[frame];
|
/* Vertex positions or deform offsets, no alpha. */
|
||||||
|
for (i = 0; i < vertexCount; i++) {
|
||||||
if (alpha < 1) {
|
|
||||||
for (i = 0; i < vertexCount; ++i) {
|
|
||||||
float prev = prevVertices[i];
|
float prev = prevVertices[i];
|
||||||
slot->attachmentVertices[i] += (prev + (nextVertices[i] - prev) * percent - slot->attachmentVertices[i]) * alpha;
|
vertices[i] = prev + (nextVertices[i] - prev) * percent;
|
||||||
|
}
|
||||||
|
} else if (setupPose) {
|
||||||
|
spVertexAttachment* vertexAttachment = SUB_CAST(spVertexAttachment, slot->attachment);
|
||||||
|
if (!vertexAttachment->bones) {
|
||||||
|
/* Unweighted vertex positions, with alpha. */
|
||||||
|
float* setupVertices = vertexAttachment->vertices;
|
||||||
|
for (i = 0; i < vertexCount; i++) {
|
||||||
|
float prev = prevVertices[i], setup = setupVertices[i];
|
||||||
|
vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < vertexCount; ++i) {
|
/* Weighted deform offsets, with alpha. */
|
||||||
|
for (i = 0; i < vertexCount; i++) {
|
||||||
float prev = prevVertices[i];
|
float prev = prevVertices[i];
|
||||||
slot->attachmentVertices[i] = prev + (nextVertices[i] - prev) * percent;
|
vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Vertex positions or deform offsets, with alpha. */
|
||||||
|
for (i = 0; i < vertexCount; i++) {
|
||||||
|
float prev = prevVertices[i];
|
||||||
|
vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user