mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
Formatting
This commit is contained in:
parent
0211519a66
commit
de6b411007
@ -299,107 +299,107 @@ float spCurveTimeline1_getCurveValue(spCurveTimeline1 *self, float time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float spCurveTimeline1_getRelativeValue(spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, float current, float setup) {
|
float spCurveTimeline1_getRelativeValue(spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, float current, float setup) {
|
||||||
float *frames = self->super.frames->items;
|
float *frames = self->super.frames->items;
|
||||||
if (time < frames[0]) {
|
if (time < frames[0]) {
|
||||||
switch (blend) {
|
switch (blend) {
|
||||||
case SP_MIX_BLEND_SETUP:
|
case SP_MIX_BLEND_SETUP:
|
||||||
return setup;
|
return setup;
|
||||||
case SP_MIX_BLEND_FIRST:
|
case SP_MIX_BLEND_FIRST:
|
||||||
return current + (setup - current) * alpha;
|
return current + (setup - current) * alpha;
|
||||||
default:
|
default:
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float value = spCurveTimeline1_getCurveValue(self, time);
|
float value = spCurveTimeline1_getCurveValue(self, time);
|
||||||
switch (blend) {
|
switch (blend) {
|
||||||
case SP_MIX_BLEND_SETUP:
|
case SP_MIX_BLEND_SETUP:
|
||||||
return setup + value * alpha;
|
return setup + value * alpha;
|
||||||
case SP_MIX_BLEND_FIRST:
|
case SP_MIX_BLEND_FIRST:
|
||||||
case SP_MIX_BLEND_REPLACE:
|
case SP_MIX_BLEND_REPLACE:
|
||||||
value += setup - current;
|
value += setup - current;
|
||||||
break;
|
break;
|
||||||
case SP_MIX_BLEND_ADD:
|
case SP_MIX_BLEND_ADD:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return current + value * alpha;
|
return current + value * alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
float spCurveTimeline1_getAbsoluteValue(spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, float current, float setup) {
|
float spCurveTimeline1_getAbsoluteValue(spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, float current, float setup) {
|
||||||
float *frames = self->super.frames->items;
|
float *frames = self->super.frames->items;
|
||||||
if (time < frames[0]) {
|
if (time < frames[0]) {
|
||||||
switch (blend) {
|
switch (blend) {
|
||||||
case SP_MIX_BLEND_SETUP:
|
case SP_MIX_BLEND_SETUP:
|
||||||
return setup;
|
return setup;
|
||||||
case SP_MIX_BLEND_FIRST:
|
case SP_MIX_BLEND_FIRST:
|
||||||
return current + (setup - current) * alpha;
|
return current + (setup - current) * alpha;
|
||||||
default:
|
default:
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float value = spCurveTimeline1_getCurveValue(self, time);
|
float value = spCurveTimeline1_getCurveValue(self, time);
|
||||||
if (blend == SP_MIX_BLEND_SETUP) return setup + (value - setup) * alpha;
|
if (blend == SP_MIX_BLEND_SETUP) return setup + (value - setup) * alpha;
|
||||||
return current + (value - current) * alpha;
|
return current + (value - current) * alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
float spCurveTimeline1_getAbsoluteValue2(spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, float current, float setup, float value) {
|
float spCurveTimeline1_getAbsoluteValue2(spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, float current, float setup, float value) {
|
||||||
float *frames = self->super.frames->items;
|
float *frames = self->super.frames->items;
|
||||||
if (time < frames[0]) {
|
if (time < frames[0]) {
|
||||||
switch (blend) {
|
switch (blend) {
|
||||||
case SP_MIX_BLEND_SETUP:
|
case SP_MIX_BLEND_SETUP:
|
||||||
return setup;
|
return setup;
|
||||||
case SP_MIX_BLEND_FIRST:
|
case SP_MIX_BLEND_FIRST:
|
||||||
return current + (setup - current) * alpha;
|
return current + (setup - current) * alpha;
|
||||||
default:
|
default:
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (blend == SP_MIX_BLEND_SETUP) return setup + (value - setup) * alpha;
|
if (blend == SP_MIX_BLEND_SETUP) return setup + (value - setup) * alpha;
|
||||||
return current + (value - current) * alpha;
|
return current + (value - current) * alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
float spCurveTimeline1_getScaleValue (spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, spMixDirection direction, float current, float setup) {
|
float spCurveTimeline1_getScaleValue(spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, spMixDirection direction, float current, float setup) {
|
||||||
float *frames = self->super.frames->items;
|
float *frames = self->super.frames->items;
|
||||||
if (time < frames[0]) {
|
if (time < frames[0]) {
|
||||||
switch (blend) {
|
switch (blend) {
|
||||||
case SP_MIX_BLEND_SETUP:
|
case SP_MIX_BLEND_SETUP:
|
||||||
return setup;
|
return setup;
|
||||||
case SP_MIX_BLEND_FIRST:
|
case SP_MIX_BLEND_FIRST:
|
||||||
return current + (setup - current) * alpha;
|
return current + (setup - current) * alpha;
|
||||||
default:
|
default:
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float value = spCurveTimeline1_getCurveValue(self, time) * setup;
|
float value = spCurveTimeline1_getCurveValue(self, time) * setup;
|
||||||
if (alpha == 1) {
|
if (alpha == 1) {
|
||||||
if (blend == SP_MIX_BLEND_ADD) return current + value - setup;
|
if (blend == SP_MIX_BLEND_ADD) return current + value - setup;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
// Mixing out uses sign of setup or current pose, else use sign of key.
|
// Mixing out uses sign of setup or current pose, else use sign of key.
|
||||||
if (direction == SP_MIX_DIRECTION_OUT) {
|
if (direction == SP_MIX_DIRECTION_OUT) {
|
||||||
switch (blend) {
|
switch (blend) {
|
||||||
case SP_MIX_BLEND_SETUP:
|
case SP_MIX_BLEND_SETUP:
|
||||||
return setup + (ABS(value) * SIGNUM(setup) - setup) * alpha;
|
return setup + (ABS(value) * SIGNUM(setup) - setup) * alpha;
|
||||||
case SP_MIX_BLEND_FIRST:
|
case SP_MIX_BLEND_FIRST:
|
||||||
case SP_MIX_BLEND_REPLACE:
|
case SP_MIX_BLEND_REPLACE:
|
||||||
return current + (ABS(value) * SIGNUM(current) - current) * alpha;
|
return current + (ABS(value) * SIGNUM(current) - current) * alpha;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
float s;
|
float s;
|
||||||
switch (blend) {
|
switch (blend) {
|
||||||
case SP_MIX_BLEND_SETUP:
|
case SP_MIX_BLEND_SETUP:
|
||||||
s = ABS(setup) * SIGNUM(value);
|
s = ABS(setup) * SIGNUM(value);
|
||||||
return s + (value - s) * alpha;
|
return s + (value - s) * alpha;
|
||||||
case SP_MIX_BLEND_FIRST:
|
case SP_MIX_BLEND_FIRST:
|
||||||
case SP_MIX_BLEND_REPLACE:
|
case SP_MIX_BLEND_REPLACE:
|
||||||
s = ABS(current) * SIGNUM(value);
|
s = ABS(current) * SIGNUM(value);
|
||||||
return s + (value - s) * alpha;
|
return s + (value - s) * alpha;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return current + (value - setup) * alpha;
|
return current + (value - setup) * alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CURVE2_ENTRIES 3
|
#define CURVE2_ENTRIES 3
|
||||||
@ -420,9 +420,9 @@ void _spRotateTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float l
|
|||||||
int *eventsCount, float alpha, spMixBlend blend, spMixDirection direction) {
|
int *eventsCount, float alpha, spMixBlend blend, spMixDirection direction) {
|
||||||
spRotateTimeline *self = SUB_CAST(spRotateTimeline, timeline);
|
spRotateTimeline *self = SUB_CAST(spRotateTimeline, timeline);
|
||||||
spBone *bone = skeleton->bones[self->boneIndex];
|
spBone *bone = skeleton->bones[self->boneIndex];
|
||||||
if (bone->active) bone->rotation = spCurveTimeline1_getRelativeValue(SUPER(self), time, alpha, blend, bone->rotation, bone->data->rotation);
|
if (bone->active) bone->rotation = spCurveTimeline1_getRelativeValue(SUPER(self), time, alpha, blend, bone->rotation, bone->data->rotation);
|
||||||
|
|
||||||
UNUSED(lastTime);
|
UNUSED(lastTime);
|
||||||
UNUSED(firedEvents);
|
UNUSED(firedEvents);
|
||||||
UNUSED(eventsCount);
|
UNUSED(eventsCount);
|
||||||
UNUSED(direction);
|
UNUSED(direction);
|
||||||
@ -787,9 +787,9 @@ void _spScaleXTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float l
|
|||||||
spScaleXTimeline *self = SUB_CAST(spScaleXTimeline, timeline);
|
spScaleXTimeline *self = SUB_CAST(spScaleXTimeline, timeline);
|
||||||
spBone *bone = skeleton->bones[self->boneIndex];
|
spBone *bone = skeleton->bones[self->boneIndex];
|
||||||
|
|
||||||
if (bone->active) bone->scaleX = spCurveTimeline1_getScaleValue(SUPER(self), time, alpha, blend, direction, bone->scaleX, bone->data->scaleX);
|
if (bone->active) bone->scaleX = spCurveTimeline1_getScaleValue(SUPER(self), time, alpha, blend, direction, bone->scaleX, bone->data->scaleX);
|
||||||
|
|
||||||
UNUSED(lastTime);
|
UNUSED(lastTime);
|
||||||
UNUSED(firedEvents);
|
UNUSED(firedEvents);
|
||||||
UNUSED(eventsCount);
|
UNUSED(eventsCount);
|
||||||
}
|
}
|
||||||
@ -816,9 +816,9 @@ void _spScaleYTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float l
|
|||||||
spScaleYTimeline *self = SUB_CAST(spScaleYTimeline, timeline);
|
spScaleYTimeline *self = SUB_CAST(spScaleYTimeline, timeline);
|
||||||
spBone *bone = skeleton->bones[self->boneIndex];
|
spBone *bone = skeleton->bones[self->boneIndex];
|
||||||
|
|
||||||
if (bone->active) bone->scaleY = spCurveTimeline1_getScaleValue(SUPER(self), time, alpha, blend, direction, bone->scaleX, bone->data->scaleY);
|
if (bone->active) bone->scaleY = spCurveTimeline1_getScaleValue(SUPER(self), time, alpha, blend, direction, bone->scaleX, bone->data->scaleY);
|
||||||
|
|
||||||
UNUSED(lastTime);
|
UNUSED(lastTime);
|
||||||
UNUSED(firedEvents);
|
UNUSED(firedEvents);
|
||||||
UNUSED(eventsCount);
|
UNUSED(eventsCount);
|
||||||
}
|
}
|
||||||
@ -934,9 +934,9 @@ void _spShearXTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float l
|
|||||||
spShearXTimeline *self = SUB_CAST(spShearXTimeline, timeline);
|
spShearXTimeline *self = SUB_CAST(spShearXTimeline, timeline);
|
||||||
spBone *bone = skeleton->bones[self->boneIndex];
|
spBone *bone = skeleton->bones[self->boneIndex];
|
||||||
|
|
||||||
if (bone->active) bone->shearX = spCurveTimeline1_getRelativeValue(SUPER(self), time, alpha, blend, bone->shearX, bone->data->shearX);
|
if (bone->active) bone->shearX = spCurveTimeline1_getRelativeValue(SUPER(self), time, alpha, blend, bone->shearX, bone->data->shearX);
|
||||||
|
|
||||||
UNUSED(lastTime);
|
UNUSED(lastTime);
|
||||||
UNUSED(firedEvents);
|
UNUSED(firedEvents);
|
||||||
UNUSED(eventsCount);
|
UNUSED(eventsCount);
|
||||||
UNUSED(direction);
|
UNUSED(direction);
|
||||||
@ -964,9 +964,9 @@ void _spShearYTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float l
|
|||||||
spShearYTimeline *self = SUB_CAST(spShearYTimeline, timeline);
|
spShearYTimeline *self = SUB_CAST(spShearYTimeline, timeline);
|
||||||
spBone *bone = skeleton->bones[self->boneIndex];
|
spBone *bone = skeleton->bones[self->boneIndex];
|
||||||
|
|
||||||
if (bone->active) bone->shearY = spCurveTimeline1_getRelativeValue(SUPER(self), time, alpha, blend, bone->shearY, bone->data->shearY);
|
if (bone->active) bone->shearY = spCurveTimeline1_getRelativeValue(SUPER(self), time, alpha, blend, bone->shearY, bone->data->shearY);
|
||||||
|
|
||||||
UNUSED(lastTime);
|
UNUSED(lastTime);
|
||||||
UNUSED(firedEvents);
|
UNUSED(firedEvents);
|
||||||
UNUSED(eventsCount);
|
UNUSED(eventsCount);
|
||||||
UNUSED(direction);
|
UNUSED(direction);
|
||||||
@ -2150,54 +2150,54 @@ void spDrawOrderTimeline_setFrame(spDrawOrderTimeline *self, int frame, float ti
|
|||||||
self->drawOrders[frame] = 0;
|
self->drawOrders[frame] = 0;
|
||||||
else {
|
else {
|
||||||
self->drawOrders[frame] = MALLOC(int, self->slotsCount);
|
self->drawOrders[frame] = MALLOC(int, self->slotsCount);
|
||||||
memcpy( self->drawOrders[frame], drawOrder, self->slotsCount * sizeof(int));
|
memcpy(self->drawOrders[frame], drawOrder, self->slotsCount * sizeof(int));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
void _spInheritTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
|
void _spInheritTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
|
||||||
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
|
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
|
||||||
spMixDirection direction) {
|
spMixDirection direction) {
|
||||||
spInheritTimeline *self = (spInheritTimeline *)timeline;
|
spInheritTimeline *self = (spInheritTimeline *) timeline;
|
||||||
spBone *bone = skeleton->bones[self->boneIndex];
|
spBone *bone = skeleton->bones[self->boneIndex];
|
||||||
float *frames = self->super.frames->items;
|
float *frames = self->super.frames->items;
|
||||||
if (!bone->active) return;
|
if (!bone->active) return;
|
||||||
|
|
||||||
if (time < frames[0]) {
|
if (time < frames[0]) {
|
||||||
if (blend == SP_MIX_BLEND_SETUP || blend == SP_MIX_BLEND_FIRST) bone->inherit = bone->data->inherit;
|
if (blend == SP_MIX_BLEND_SETUP || blend == SP_MIX_BLEND_FIRST) bone->inherit = bone->data->inherit;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int idx = search2(self->super.frames, time, 2) + 1;
|
int idx = search2(self->super.frames, time, 2) + 1;
|
||||||
bone->inherit = (spInherit) frames[idx];
|
bone->inherit = (spInherit) frames[idx];
|
||||||
|
|
||||||
UNUSED(lastTime);
|
UNUSED(lastTime);
|
||||||
UNUSED(firedEvents);
|
UNUSED(firedEvents);
|
||||||
UNUSED(eventsCount);
|
UNUSED(eventsCount);
|
||||||
UNUSED(alpha);
|
UNUSED(alpha);
|
||||||
UNUSED(direction);
|
UNUSED(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _spInheritTimeline_dispose(spTimeline *timeline) {
|
void _spInheritTimeline_dispose(spTimeline *timeline) {
|
||||||
// no-op, spTimeline_dispose disposes frames.
|
// no-op, spTimeline_dispose disposes frames.
|
||||||
UNUSED(timeline);
|
UNUSED(timeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
spInheritTimeline *spInheritTimeline_create(int framesCount, int boneIndex) {
|
spInheritTimeline *spInheritTimeline_create(int framesCount, int boneIndex) {
|
||||||
spInheritTimeline *self = NEW(spInheritTimeline);
|
spInheritTimeline *self = NEW(spInheritTimeline);
|
||||||
spPropertyId ids[1];
|
spPropertyId ids[1];
|
||||||
ids[0] = (spPropertyId) SP_PROPERTY_INHERIT << 32;
|
ids[0] = (spPropertyId) SP_PROPERTY_INHERIT << 32;
|
||||||
_spTimeline_init(SUPER(self), framesCount, 2, ids, 1, SP_TIMELINE_INHERIT, _spInheritTimeline_dispose,
|
_spTimeline_init(SUPER(self), framesCount, 2, ids, 1, SP_TIMELINE_INHERIT, _spInheritTimeline_dispose,
|
||||||
_spInheritTimeline_apply, 0);
|
_spInheritTimeline_apply, 0);
|
||||||
|
|
||||||
self->boneIndex = boneIndex;
|
self->boneIndex = boneIndex;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spInheritTimeline_setFrame(spInheritTimeline *self, int frame, float time, spInherit inherit) {
|
void spInheritTimeline_setFrame(spInheritTimeline *self, int frame, float time, spInherit inherit) {
|
||||||
frame *= 2;
|
frame *= 2;
|
||||||
self->super.frames->items[frame] = time;
|
self->super.frames->items[frame] = time;
|
||||||
self->super.frames->items[frame + 1] = inherit;
|
self->super.frames->items[frame + 1] = inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2464,9 +2464,9 @@ static const int PATHCONSTRAINTPOSITION_VALUE = 1;
|
|||||||
void _spPathConstraintPositionTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
|
void _spPathConstraintPositionTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
|
||||||
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
|
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
|
||||||
spMixDirection direction) {
|
spMixDirection direction) {
|
||||||
spPathConstraintPositionTimeline *self = (spPathConstraintPositionTimeline *) timeline;
|
spPathConstraintPositionTimeline *self = (spPathConstraintPositionTimeline *) timeline;
|
||||||
spPathConstraint *constraint = skeleton->pathConstraints[self->pathConstraintIndex];
|
spPathConstraint *constraint = skeleton->pathConstraints[self->pathConstraintIndex];
|
||||||
if (constraint->active) constraint->position = spCurveTimeline1_getAbsoluteValue(SUPER(self), time, alpha, blend, constraint->position, constraint->data->position);
|
if (constraint->active) constraint->position = spCurveTimeline1_getAbsoluteValue(SUPER(self), time, alpha, blend, constraint->position, constraint->data->position);
|
||||||
|
|
||||||
UNUSED(lastTime);
|
UNUSED(lastTime);
|
||||||
UNUSED(firedEvents);
|
UNUSED(firedEvents);
|
||||||
@ -2500,14 +2500,14 @@ static const int PATHCONSTRAINTSPACING_VALUE = 1;
|
|||||||
void _spPathConstraintSpacingTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
|
void _spPathConstraintSpacingTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
|
||||||
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
|
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
|
||||||
spMixDirection direction) {
|
spMixDirection direction) {
|
||||||
spPathConstraintSpacingTimeline *self = (spPathConstraintSpacingTimeline *) timeline;
|
spPathConstraintSpacingTimeline *self = (spPathConstraintSpacingTimeline *) timeline;
|
||||||
spPathConstraint *constraint = skeleton->pathConstraints[self->pathConstraintIndex];
|
spPathConstraint *constraint = skeleton->pathConstraints[self->pathConstraintIndex];
|
||||||
if (constraint->active) constraint->spacing = spCurveTimeline1_getAbsoluteValue(SUPER(self), time, alpha, blend, constraint->spacing, constraint->data->spacing);
|
if (constraint->active) constraint->spacing = spCurveTimeline1_getAbsoluteValue(SUPER(self), time, alpha, blend, constraint->spacing, constraint->data->spacing);
|
||||||
|
|
||||||
UNUSED(lastTime);
|
UNUSED(lastTime);
|
||||||
UNUSED(firedEvents);
|
UNUSED(firedEvents);
|
||||||
UNUSED(eventsCount);
|
UNUSED(eventsCount);
|
||||||
UNUSED(direction);
|
UNUSED(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
spPathConstraintSpacingTimeline *
|
spPathConstraintSpacingTimeline *
|
||||||
@ -2640,223 +2640,223 @@ void spPathConstraintMixTimeline_setFrame(spPathConstraintMixTimeline *self, int
|
|||||||
|
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
int/*bool*/ _spPhysicsConstraintTimeline_global(spPhysicsConstraintData *data, spTimelineType type) {
|
int /*bool*/ _spPhysicsConstraintTimeline_global(spPhysicsConstraintData *data, spTimelineType type) {
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
|
||||||
return data->inertiaGlobal;
|
return data->inertiaGlobal;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
|
||||||
return data->strengthGlobal;
|
return data->strengthGlobal;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
|
||||||
return data->dampingGlobal;
|
return data->dampingGlobal;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
|
||||||
return data->massGlobal;
|
return data->massGlobal;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
|
||||||
return data->windGlobal;
|
return data->windGlobal;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
|
||||||
return data->gravityGlobal;
|
return data->gravityGlobal;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
|
||||||
return data->mixGlobal;
|
return data->mixGlobal;
|
||||||
default:
|
default:
|
||||||
// should never happen
|
// should never happen
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _spPhysicsConstraintTimeline_set(spPhysicsConstraint *constraint, spTimelineType type, float value) {
|
void _spPhysicsConstraintTimeline_set(spPhysicsConstraint *constraint, spTimelineType type, float value) {
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
|
||||||
constraint->inertia = value;
|
constraint->inertia = value;
|
||||||
break;
|
break;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
|
||||||
constraint->strength = value;
|
constraint->strength = value;
|
||||||
break;
|
break;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
|
||||||
constraint->damping = value;
|
constraint->damping = value;
|
||||||
break;
|
break;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
|
||||||
constraint->massInverse = value;
|
constraint->massInverse = value;
|
||||||
break;
|
break;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
|
||||||
constraint->wind = value;
|
constraint->wind = value;
|
||||||
break;
|
break;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
|
||||||
constraint->gravity = value;
|
constraint->gravity = value;
|
||||||
break;
|
break;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
|
||||||
constraint->mix = value;
|
constraint->mix = value;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// should never happen
|
// should never happen
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float _spPhysicsConstraintTimeline_get(spPhysicsConstraint *constraint, spTimelineType type) {
|
float _spPhysicsConstraintTimeline_get(spPhysicsConstraint *constraint, spTimelineType type) {
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
|
||||||
return constraint->inertia;
|
return constraint->inertia;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
|
||||||
return constraint->strength;
|
return constraint->strength;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
|
||||||
return constraint->damping;
|
return constraint->damping;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
|
||||||
return constraint->massInverse;
|
return constraint->massInverse;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
|
||||||
return constraint->wind;
|
return constraint->wind;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
|
||||||
return constraint->gravity;
|
return constraint->gravity;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
|
||||||
return constraint->mix;
|
return constraint->mix;
|
||||||
default:
|
default:
|
||||||
// should never happen
|
// should never happen
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float _spPhysicsConstraintTimeline_setup(spPhysicsConstraint *constraint, spTimelineType type) {
|
float _spPhysicsConstraintTimeline_setup(spPhysicsConstraint *constraint, spTimelineType type) {
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
|
||||||
return constraint->data->inertia;
|
return constraint->data->inertia;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
|
||||||
return constraint->data->strength;
|
return constraint->data->strength;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
|
||||||
return constraint->data->damping;
|
return constraint->data->damping;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
|
||||||
return constraint->data->massInverse;
|
return constraint->data->massInverse;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
|
||||||
return constraint->data->wind;
|
return constraint->data->wind;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
|
||||||
return constraint->data->gravity;
|
return constraint->data->gravity;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
|
||||||
return constraint->data->mix;
|
return constraint->data->mix;
|
||||||
default:
|
default:
|
||||||
// should never happen
|
// should never happen
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _spPhysicsConstraintTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
|
void _spPhysicsConstraintTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
|
||||||
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
|
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
|
||||||
spMixDirection direction) {
|
spMixDirection direction) {
|
||||||
spPhysicsConstraintTimeline *self = SUB_CAST(spPhysicsConstraintTimeline, timeline);
|
spPhysicsConstraintTimeline *self = SUB_CAST(spPhysicsConstraintTimeline, timeline);
|
||||||
spTimelineType type = self->super.super.type;
|
spTimelineType type = self->super.super.type;
|
||||||
float *frames = self->super.super.frames->items;
|
float *frames = self->super.super.frames->items;
|
||||||
if (self->physicsConstraintIndex == -1) {
|
if (self->physicsConstraintIndex == -1) {
|
||||||
float value = time >= frames[0] ? spCurveTimeline1_getCurveValue(SUPER(self), time) : 0;
|
float value = time >= frames[0] ? spCurveTimeline1_getCurveValue(SUPER(self), time) : 0;
|
||||||
|
|
||||||
spPhysicsConstraint **physicsConstraints = skeleton->physicsConstraints;
|
spPhysicsConstraint **physicsConstraints = skeleton->physicsConstraints;
|
||||||
for (int i = 0; i < skeleton->physicsConstraintsCount; i++) {
|
for (int i = 0; i < skeleton->physicsConstraintsCount; i++) {
|
||||||
spPhysicsConstraint *constraint = physicsConstraints[i];
|
spPhysicsConstraint *constraint = physicsConstraints[i];
|
||||||
if (constraint->active && _spPhysicsConstraintTimeline_global(constraint->data, type))
|
if (constraint->active && _spPhysicsConstraintTimeline_global(constraint->data, type))
|
||||||
_spPhysicsConstraintTimeline_set(constraint, type,spCurveTimeline1_getAbsoluteValue2(SUPER(self), time, alpha, blend, _spPhysicsConstraintTimeline_get(constraint, type), _spPhysicsConstraintTimeline_setup(constraint, type), value));
|
_spPhysicsConstraintTimeline_set(constraint, type, spCurveTimeline1_getAbsoluteValue2(SUPER(self), time, alpha, blend, _spPhysicsConstraintTimeline_get(constraint, type), _spPhysicsConstraintTimeline_setup(constraint, type), value));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
spPhysicsConstraint *constraint = skeleton->physicsConstraints[self->physicsConstraintIndex];
|
spPhysicsConstraint *constraint = skeleton->physicsConstraints[self->physicsConstraintIndex];
|
||||||
if (constraint->active) _spPhysicsConstraintTimeline_set(constraint, type, spCurveTimeline1_getAbsoluteValue(SUPER(self), time, alpha, blend, _spPhysicsConstraintTimeline_get(constraint, type), _spPhysicsConstraintTimeline_setup(constraint, type)));
|
if (constraint->active) _spPhysicsConstraintTimeline_set(constraint, type, spCurveTimeline1_getAbsoluteValue(SUPER(self), time, alpha, blend, _spPhysicsConstraintTimeline_get(constraint, type), _spPhysicsConstraintTimeline_setup(constraint, type)));
|
||||||
}
|
}
|
||||||
UNUSED(lastTime);
|
UNUSED(lastTime);
|
||||||
UNUSED(firedEvents);
|
UNUSED(firedEvents);
|
||||||
UNUSED(eventsCount);
|
UNUSED(eventsCount);
|
||||||
UNUSED(direction);
|
UNUSED(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
spPhysicsConstraintTimeline *
|
spPhysicsConstraintTimeline *
|
||||||
spPhysicsConstraintTimeline_create(int frameCount, int bezierCount, int physicsConstraintIndex, spTimelineType type) {
|
spPhysicsConstraintTimeline_create(int frameCount, int bezierCount, int physicsConstraintIndex, spTimelineType type) {
|
||||||
spPhysicsConstraintTimeline *timeline = NEW(spPhysicsConstraintTimeline);
|
spPhysicsConstraintTimeline *timeline = NEW(spPhysicsConstraintTimeline);
|
||||||
spPropertyId ids[1];
|
spPropertyId ids[1];
|
||||||
spPropertyId id;
|
spPropertyId id;
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
|
||||||
id = SP_PROPERTY_PHYSICSCONSTRAINT_INERTIA;
|
id = SP_PROPERTY_PHYSICSCONSTRAINT_INERTIA;
|
||||||
break;
|
break;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
|
||||||
id = SP_PROPERTY_PHYSICSCONSTRAINT_STRENGTH;
|
id = SP_PROPERTY_PHYSICSCONSTRAINT_STRENGTH;
|
||||||
break;
|
break;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
|
||||||
id = SP_PROPERTY_PHYSICSCONSTRAINT_DAMPING;
|
id = SP_PROPERTY_PHYSICSCONSTRAINT_DAMPING;
|
||||||
break;
|
break;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
|
||||||
id = SP_PROPERTY_PHYSICSCONSTRAINT_MASS;
|
id = SP_PROPERTY_PHYSICSCONSTRAINT_MASS;
|
||||||
break;
|
break;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
|
||||||
id = SP_PROPERTY_PHYSICSCONSTRAINT_WIND;
|
id = SP_PROPERTY_PHYSICSCONSTRAINT_WIND;
|
||||||
break;
|
break;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
|
||||||
id = SP_PROPERTY_PHYSICSCONSTRAINT_GRAVITY;
|
id = SP_PROPERTY_PHYSICSCONSTRAINT_GRAVITY;
|
||||||
break;
|
break;
|
||||||
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
|
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
|
||||||
id = SP_PROPERTY_PHYSICSCONSTRAINT_MIX;
|
id = SP_PROPERTY_PHYSICSCONSTRAINT_MIX;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// should never happen
|
// should never happen
|
||||||
id = SP_PROPERTY_PHYSICSCONSTRAINT_INERTIA;
|
id = SP_PROPERTY_PHYSICSCONSTRAINT_INERTIA;
|
||||||
}
|
}
|
||||||
ids[0] = ((spPropertyId) id << 32) | physicsConstraintIndex;
|
ids[0] = ((spPropertyId) id << 32) | physicsConstraintIndex;
|
||||||
_spCurveTimeline_init(SUPER(timeline), frameCount, CURVE1_ENTRIES, bezierCount, ids, 1, type,
|
_spCurveTimeline_init(SUPER(timeline), frameCount, CURVE1_ENTRIES, bezierCount, ids, 1, type,
|
||||||
_spCurveTimeline_dispose, _spPhysicsConstraintTimeline_apply, _spCurveTimeline_setBezier);
|
_spCurveTimeline_dispose, _spPhysicsConstraintTimeline_apply, _spCurveTimeline_setBezier);
|
||||||
timeline->physicsConstraintIndex = physicsConstraintIndex;
|
timeline->physicsConstraintIndex = physicsConstraintIndex;
|
||||||
return timeline;
|
return timeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spPhysicsConstraintTimeline_setFrame(spPhysicsConstraintTimeline *self, int frame, float time, float value) {
|
void spPhysicsConstraintTimeline_setFrame(spPhysicsConstraintTimeline *self, int frame, float time, float value) {
|
||||||
spCurveTimeline1_setFrame(SUPER(self), frame, time, value);
|
spCurveTimeline1_setFrame(SUPER(self), frame, time, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
void _spPhysicsConstraintResetTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
|
void _spPhysicsConstraintResetTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
|
||||||
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
|
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
|
||||||
spMixDirection direction) {
|
spMixDirection direction) {
|
||||||
spPhysicsConstraintResetTimeline *self = (spPhysicsConstraintResetTimeline *)timeline;
|
spPhysicsConstraintResetTimeline *self = (spPhysicsConstraintResetTimeline *) timeline;
|
||||||
spPhysicsConstraint *constraint = NULL;
|
spPhysicsConstraint *constraint = NULL;
|
||||||
if (self->physicsConstraintIndex != -1) {
|
if (self->physicsConstraintIndex != -1) {
|
||||||
constraint = skeleton->physicsConstraints[self->physicsConstraintIndex];
|
constraint = skeleton->physicsConstraints[self->physicsConstraintIndex];
|
||||||
if (!constraint->active) return;
|
if (!constraint->active) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float *frames = SUPER(self)->frames->items;
|
float *frames = SUPER(self)->frames->items;
|
||||||
if (lastTime > time) {// Apply after lastTime for looped animations.
|
if (lastTime > time) {// Apply after lastTime for looped animations.
|
||||||
_spPhysicsConstraintResetTimeline_apply(SUPER(self), skeleton, lastTime, INT_MAX, NULL, 0, alpha, blend, direction);
|
_spPhysicsConstraintResetTimeline_apply(SUPER(self), skeleton, lastTime, INT_MAX, NULL, 0, alpha, blend, direction);
|
||||||
lastTime = -1;
|
lastTime = -1;
|
||||||
} else if (lastTime >= frames[SUPER(self)->frameCount - 1])// Last time is after last frame.
|
} else if (lastTime >= frames[SUPER(self)->frameCount - 1])// Last time is after last frame.
|
||||||
return;
|
return;
|
||||||
if (time < frames[0]) return;
|
if (time < frames[0]) return;
|
||||||
|
|
||||||
if (lastTime < frames[0] || time >= frames[search(self->super.frames, lastTime) + 1]) {
|
if (lastTime < frames[0] || time >= frames[search(self->super.frames, lastTime) + 1]) {
|
||||||
if (constraint != NULL)
|
if (constraint != NULL)
|
||||||
spPhysicsConstraint_reset(constraint);
|
spPhysicsConstraint_reset(constraint);
|
||||||
else {
|
else {
|
||||||
spPhysicsConstraint **physicsConstraints = skeleton->physicsConstraints;
|
spPhysicsConstraint **physicsConstraints = skeleton->physicsConstraints;
|
||||||
for (int i = 0; i < skeleton->physicsConstraintsCount; i++) {
|
for (int i = 0; i < skeleton->physicsConstraintsCount; i++) {
|
||||||
constraint = physicsConstraints[i];
|
constraint = physicsConstraints[i];
|
||||||
if (constraint->active) spPhysicsConstraint_reset(constraint);
|
if (constraint->active) spPhysicsConstraint_reset(constraint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UNUSED(lastTime);
|
UNUSED(lastTime);
|
||||||
UNUSED(firedEvents);
|
UNUSED(firedEvents);
|
||||||
UNUSED(eventsCount);
|
UNUSED(eventsCount);
|
||||||
UNUSED(alpha);
|
UNUSED(alpha);
|
||||||
UNUSED(direction);
|
UNUSED(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _spPhysicsConstraintResetTimeline_dispose(spTimeline *timeline) {
|
void _spPhysicsConstraintResetTimeline_dispose(spTimeline *timeline) {
|
||||||
// no-op, spTimeline_dispose disposes frames.
|
// no-op, spTimeline_dispose disposes frames.
|
||||||
UNUSED(timeline);
|
UNUSED(timeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
spPhysicsConstraintResetTimeline *spPhysicsConstraintResetTimeline_create(int framesCount, int physicsConstraintIndex) {
|
spPhysicsConstraintResetTimeline *spPhysicsConstraintResetTimeline_create(int framesCount, int physicsConstraintIndex) {
|
||||||
spPhysicsConstraintResetTimeline *self = NEW(spPhysicsConstraintResetTimeline);
|
spPhysicsConstraintResetTimeline *self = NEW(spPhysicsConstraintResetTimeline);
|
||||||
spPropertyId ids[1];
|
spPropertyId ids[1];
|
||||||
ids[0] = (spPropertyId) SP_PROPERTY_PHYSICSCONSTRAINT_RESET << 32;
|
ids[0] = (spPropertyId) SP_PROPERTY_PHYSICSCONSTRAINT_RESET << 32;
|
||||||
_spTimeline_init(SUPER(self), framesCount, 1, ids, 1, SP_TIMELINE_PHYSICSCONSTRAINT_RESET, _spPhysicsConstraintResetTimeline_dispose,
|
_spTimeline_init(SUPER(self), framesCount, 1, ids, 1, SP_TIMELINE_PHYSICSCONSTRAINT_RESET, _spPhysicsConstraintResetTimeline_dispose,
|
||||||
_spPhysicsConstraintResetTimeline_apply, 0);
|
_spPhysicsConstraintResetTimeline_apply, 0);
|
||||||
|
|
||||||
self->physicsConstraintIndex = physicsConstraintIndex;
|
self->physicsConstraintIndex = physicsConstraintIndex;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spPhysicsConstraintResetTimeline_setFrame(spPhysicsConstraintResetTimeline *self, int frame, float time) {
|
void spPhysicsConstraintResetTimeline_setFrame(spPhysicsConstraintResetTimeline *self, int frame, float time) {
|
||||||
self->super.frames->items[frame] = time;
|
self->super.frames->items[frame] = time;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -399,10 +399,10 @@ int spAnimationState_apply(spAnimationState *self, spSkeleton *skeleton) {
|
|||||||
/* Apply mixing from entries first. */
|
/* Apply mixing from entries first. */
|
||||||
alpha = current->alpha;
|
alpha = current->alpha;
|
||||||
if (current->mixingFrom)
|
if (current->mixingFrom)
|
||||||
alpha *= _spAnimationState_applyMixingFrom(self, current, skeleton, blend);
|
alpha *= _spAnimationState_applyMixingFrom(self, current, skeleton, blend);
|
||||||
else if (current->trackTime >= current->trackEnd && current->next == 0)
|
else if (current->trackTime >= current->trackEnd && current->next == 0)
|
||||||
alpha = 0;
|
alpha = 0;
|
||||||
int/*bool*/ attachments = alpha >= current->alphaAttachmentThreshold;
|
int /*bool*/ attachments = alpha >= current->alphaAttachmentThreshold;
|
||||||
|
|
||||||
/* Apply current entry. */
|
/* Apply current entry. */
|
||||||
animationLast = current->animationLast;
|
animationLast = current->animationLast;
|
||||||
@ -422,7 +422,7 @@ int spAnimationState_apply(spAnimationState *self, spSkeleton *skeleton) {
|
|||||||
_spAnimationState_applyAttachmentTimeline(self, timeline, skeleton, applyTime, blend, attachments);
|
_spAnimationState_applyAttachmentTimeline(self, timeline, skeleton, applyTime, blend, attachments);
|
||||||
} else {
|
} else {
|
||||||
spTimeline_apply(timelines[ii], skeleton, animationLast, applyTime, applyEvents,
|
spTimeline_apply(timelines[ii], skeleton, animationLast, applyTime, applyEvents,
|
||||||
&internal->eventsCount, alpha, blend, SP_MIX_DIRECTION_IN);
|
&internal->eventsCount, alpha, blend, SP_MIX_DIRECTION_IN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -438,12 +438,12 @@ int spAnimationState_apply(spAnimationState *self, spSkeleton *skeleton) {
|
|||||||
timelineBlend = timelineMode->items[ii] == SUBSEQUENT ? blend : SP_MIX_BLEND_SETUP;
|
timelineBlend = timelineMode->items[ii] == SUBSEQUENT ? blend : SP_MIX_BLEND_SETUP;
|
||||||
if (!shortestRotation && timeline->type == SP_TIMELINE_ROTATE)
|
if (!shortestRotation && timeline->type == SP_TIMELINE_ROTATE)
|
||||||
_spAnimationState_applyRotateTimeline(self, timeline, skeleton, applyTime, alpha, timelineBlend,
|
_spAnimationState_applyRotateTimeline(self, timeline, skeleton, applyTime, alpha, timelineBlend,
|
||||||
timelinesRotation, ii << 1, firstFrame);
|
timelinesRotation, ii << 1, firstFrame);
|
||||||
else if (timeline->type == SP_TIMELINE_ATTACHMENT)
|
else if (timeline->type == SP_TIMELINE_ATTACHMENT)
|
||||||
_spAnimationState_applyAttachmentTimeline(self, timeline, skeleton, applyTime, timelineBlend, attachments);
|
_spAnimationState_applyAttachmentTimeline(self, timeline, skeleton, applyTime, timelineBlend, attachments);
|
||||||
else
|
else
|
||||||
spTimeline_apply(timeline, skeleton, animationLast, applyTime, applyEvents, &internal->eventsCount,
|
spTimeline_apply(timeline, skeleton, animationLast, applyTime, applyEvents, &internal->eventsCount,
|
||||||
alpha, timelineBlend, SP_MIX_DIRECTION_IN);
|
alpha, timelineBlend, SP_MIX_DIRECTION_IN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_spAnimationState_queueEvents(self, current, animationTime);
|
_spAnimationState_queueEvents(self, current, animationTime);
|
||||||
@ -665,8 +665,8 @@ void _spAnimationState_applyRotateTimeline(spAnimationState *self, spTimeline *t
|
|||||||
|
|
||||||
/* Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. */
|
/* Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. */
|
||||||
diff = r2 - r1;
|
diff = r2 - r1;
|
||||||
diff -= CEIL(diff / 360 - 0.5) * 360;
|
diff -= CEIL(diff / 360 - 0.5) * 360;
|
||||||
if (diff == 0) {
|
if (diff == 0) {
|
||||||
total = timelinesRotation[i];
|
total = timelinesRotation[i];
|
||||||
} else {
|
} else {
|
||||||
float lastTotal, lastDiff, loops;
|
float lastTotal, lastDiff, loops;
|
||||||
@ -716,15 +716,15 @@ void _spAnimationState_queueEvents(spAnimationState *self, spTrackEntry *entry,
|
|||||||
|
|
||||||
/* Queue complete if completed a loop iteration or the animation. */
|
/* Queue complete if completed a loop iteration or the animation. */
|
||||||
if (entry->loop) {
|
if (entry->loop) {
|
||||||
if (duration == 0)
|
if (duration == 0)
|
||||||
complete = -1;
|
complete = -1;
|
||||||
else {
|
else {
|
||||||
int cycles = (int) (entry->trackTime / duration);
|
int cycles = (int) (entry->trackTime / duration);
|
||||||
complete = cycles > 0 && cycles > (int) (entry->trackLast / duration);
|
complete = cycles > 0 && cycles > (int) (entry->trackLast / duration);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
complete = (animationTime >= animationEnd && entry->animationLast < animationEnd);
|
complete = (animationTime >= animationEnd && entry->animationLast < animationEnd);
|
||||||
}
|
}
|
||||||
if (complete) _spEventQueue_complete(internal->queue, entry);
|
if (complete) _spEventQueue_complete(internal->queue, entry);
|
||||||
|
|
||||||
/* Queue events after complete. */
|
/* Queue events after complete. */
|
||||||
@ -918,7 +918,7 @@ _spAnimationState_trackEntry(spAnimationState *self, int trackIndex, spAnimation
|
|||||||
|
|
||||||
entry->eventThreshold = 0;
|
entry->eventThreshold = 0;
|
||||||
entry->mixAttachmentThreshold = 0;
|
entry->mixAttachmentThreshold = 0;
|
||||||
entry->alphaAttachmentThreshold = 0;
|
entry->alphaAttachmentThreshold = 0;
|
||||||
entry->mixDrawOrderThreshold = 0;
|
entry->mixDrawOrderThreshold = 0;
|
||||||
|
|
||||||
entry->animationStart = 0;
|
entry->animationStart = 0;
|
||||||
@ -1060,13 +1060,13 @@ float spTrackEntry_getTrackComplete(spTrackEntry *entry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spTrackEntry_setMixDuration(spTrackEntry *entry, float mixDuration, float delay) {
|
void spTrackEntry_setMixDuration(spTrackEntry *entry, float mixDuration, float delay) {
|
||||||
entry->mixDuration = mixDuration;
|
entry->mixDuration = mixDuration;
|
||||||
if (entry->previous && delay <= 0) delay += spTrackEntry_getTrackComplete(entry) - mixDuration;
|
if (entry->previous && delay <= 0) delay += spTrackEntry_getTrackComplete(entry) - mixDuration;
|
||||||
entry->delay = delay;
|
entry->delay = delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spTrackEntry_wasApplied(spTrackEntry *entry) {
|
int spTrackEntry_wasApplied(spTrackEntry *entry) {
|
||||||
return entry->nextTrackLast != -1;
|
return entry->nextTrackLast != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _spTrackEntry_computeHold(spTrackEntry *entry, spAnimationState *state) {
|
void _spTrackEntry_computeHold(spTrackEntry *entry, spAnimationState *state) {
|
||||||
|
|||||||
@ -48,8 +48,8 @@ spBone *spBone_create(spBoneData *data, spSkeleton *skeleton, spBone *parent) {
|
|||||||
self->parent = parent;
|
self->parent = parent;
|
||||||
self->a = 1.0f;
|
self->a = 1.0f;
|
||||||
self->d = 1.0f;
|
self->d = 1.0f;
|
||||||
self->active = -1;
|
self->active = -1;
|
||||||
self->inherit = SP_INHERIT_NORMAL;
|
self->inherit = SP_INHERIT_NORMAL;
|
||||||
spBone_setToSetupPose(self);
|
spBone_setToSetupPose(self);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -70,10 +70,10 @@ void spBone_updateWorldTransform(spBone *self) {
|
|||||||
|
|
||||||
void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotation, float scaleX, float scaleY,
|
void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotation, float scaleX, float scaleY,
|
||||||
float shearX, float shearY) {
|
float shearX, float shearY) {
|
||||||
float pa, pb, pc, pd;
|
float pa, pb, pc, pd;
|
||||||
float sx = self->skeleton->scaleX;
|
float sx = self->skeleton->scaleX;
|
||||||
float sy = self->skeleton->scaleY * (spBone_isYDown() ? -1 : 1);
|
float sy = self->skeleton->scaleY * (spBone_isYDown() ? -1 : 1);
|
||||||
spBone *parent = self->parent;
|
spBone *parent = self->parent;
|
||||||
|
|
||||||
self->ax = x;
|
self->ax = x;
|
||||||
self->ay = y;
|
self->ay = y;
|
||||||
@ -84,14 +84,14 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
|
|||||||
self->ashearY = shearY;
|
self->ashearY = shearY;
|
||||||
|
|
||||||
if (!parent) { /* Root bone. */
|
if (!parent) { /* Root bone. */
|
||||||
float rx = (rotation + shearX) * DEG_RAD;
|
float rx = (rotation + shearX) * DEG_RAD;
|
||||||
float ry = (rotation + 90 + shearY) * DEG_RAD;
|
float ry = (rotation + 90 + shearY) * DEG_RAD;
|
||||||
self->a = COS(rx) * scaleX * sx;
|
self->a = COS(rx) * scaleX * sx;
|
||||||
self->b = COS(ry) * scaleY * sx;
|
self->b = COS(ry) * scaleY * sx;
|
||||||
self->c = SIN(rx) * scaleX * sy;
|
self->c = SIN(rx) * scaleX * sy;
|
||||||
self->d = SIN(ry) * scaleY * sy;
|
self->d = SIN(ry) * scaleY * sy;
|
||||||
self->worldX = x * sx + self->skeleton->x;
|
self->worldX = x * sx + self->skeleton->x;
|
||||||
self->worldY = y * sy + self->skeleton->y;
|
self->worldY = y * sy + self->skeleton->y;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,12 +105,12 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
|
|||||||
|
|
||||||
switch (self->inherit) {
|
switch (self->inherit) {
|
||||||
case SP_INHERIT_NORMAL: {
|
case SP_INHERIT_NORMAL: {
|
||||||
float rx = (rotation + shearX) * DEG_RAD;
|
float rx = (rotation + shearX) * DEG_RAD;
|
||||||
float ry = (rotation + 90 + shearY) * DEG_RAD;
|
float ry = (rotation + 90 + shearY) * DEG_RAD;
|
||||||
float la = COS(rx) * scaleX;
|
float la = COS(rx) * scaleX;
|
||||||
float lb = COS(ry) * scaleY;
|
float lb = COS(ry) * scaleY;
|
||||||
float lc = SIN(rx) * scaleX;
|
float lc = SIN(rx) * scaleX;
|
||||||
float ld = SIN(ry) * scaleY;
|
float ld = SIN(ry) * scaleY;
|
||||||
self->a = pa * la + pb * lc;
|
self->a = pa * la + pb * lc;
|
||||||
self->b = pa * lb + pb * ld;
|
self->b = pa * lb + pb * ld;
|
||||||
self->c = pc * la + pd * lc;
|
self->c = pc * la + pd * lc;
|
||||||
@ -118,12 +118,12 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case SP_INHERIT_ONLYTRANSLATION: {
|
case SP_INHERIT_ONLYTRANSLATION: {
|
||||||
float rx = (rotation + shearX) * DEG_RAD;
|
float rx = (rotation + shearX) * DEG_RAD;
|
||||||
float ry = (rotation + 90 + shearY) * DEG_RAD;
|
float ry = (rotation + 90 + shearY) * DEG_RAD;
|
||||||
self->a = COS(rx) * scaleX;
|
self->a = COS(rx) * scaleX;
|
||||||
self->b = COS(ry) * scaleY;
|
self->b = COS(ry) * scaleY;
|
||||||
self->c = SIN(rx) * scaleX;
|
self->c = SIN(rx) * scaleX;
|
||||||
self->d = SIN(ry) * scaleY;
|
self->d = SIN(ry) * scaleY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SP_INHERIT_NOROTATIONORREFLECTION: {
|
case SP_INHERIT_NOROTATIONORREFLECTION: {
|
||||||
@ -141,12 +141,12 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
|
|||||||
pc = 0;
|
pc = 0;
|
||||||
prx = 90 - ATAN2DEG(pd, pb);
|
prx = 90 - ATAN2DEG(pd, pb);
|
||||||
}
|
}
|
||||||
float rx = (rotation + shearX - prx) *DEG_RAD;
|
float rx = (rotation + shearX - prx) * DEG_RAD;
|
||||||
float ry = (rotation + shearY - prx + 90) *DEG_RAD;
|
float ry = (rotation + shearY - prx + 90) * DEG_RAD;
|
||||||
float la = COS(rx) * scaleX;
|
float la = COS(rx) * scaleX;
|
||||||
float lb = COS(ry) * scaleY;
|
float lb = COS(ry) * scaleY;
|
||||||
float lc = SIN(rx) * scaleX;
|
float lc = SIN(rx) * scaleX;
|
||||||
float ld = SIN(ry) * scaleY;
|
float ld = SIN(ry) * scaleY;
|
||||||
self->a = pa * la - pb * lc;
|
self->a = pa * la - pb * lc;
|
||||||
self->b = pa * lb - pb * ld;
|
self->b = pa * lb - pb * ld;
|
||||||
self->c = pc * la + pd * lc;
|
self->c = pc * la + pd * lc;
|
||||||
@ -155,23 +155,23 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
|
|||||||
}
|
}
|
||||||
case SP_INHERIT_NOSCALE:
|
case SP_INHERIT_NOSCALE:
|
||||||
case SP_INHERIT_NOSCALEORREFLECTION: {
|
case SP_INHERIT_NOSCALEORREFLECTION: {
|
||||||
rotation *= DEG_RAD;
|
rotation *= DEG_RAD;
|
||||||
float cosine = COS(rotation);
|
float cosine = COS(rotation);
|
||||||
float sine = SIN(rotation);
|
float sine = SIN(rotation);
|
||||||
float za = (pa * cosine + pb * sine) / sx;
|
float za = (pa * cosine + pb * sine) / sx;
|
||||||
float zc = (pc * cosine + pd * sine) / sy;
|
float zc = (pc * cosine + pd * sine) / sy;
|
||||||
float s = SQRT(za * za + zc * zc);
|
float s = SQRT(za * za + zc * zc);
|
||||||
if (self->data->inherit == SP_INHERIT_NOSCALE && (pa * pd - pb * pc < 0) != (sx < 0 != sy < 0))
|
if (self->data->inherit == SP_INHERIT_NOSCALE && (pa * pd - pb * pc < 0) != (sx < 0 != sy < 0))
|
||||||
s = -s;
|
s = -s;
|
||||||
rotation = PI / 2 + ATAN2(zc, za);
|
rotation = PI / 2 + ATAN2(zc, za);
|
||||||
float zb = COS(rotation) * s;
|
float zb = COS(rotation) * s;
|
||||||
float zd = SIN(rotation) * s;
|
float zd = SIN(rotation) * s;
|
||||||
shearX *= DEG_RAD;
|
shearX *= DEG_RAD;
|
||||||
shearY = (90 + shearY) * DEG_RAD;
|
shearY = (90 + shearY) * DEG_RAD;
|
||||||
float la = COS(shearX) * scaleX;
|
float la = COS(shearX) * scaleX;
|
||||||
float lb = COS(shearY) * scaleY;
|
float lb = COS(shearY) * scaleY;
|
||||||
float lc = SIN(shearX) * scaleX;
|
float lc = SIN(shearX) * scaleX;
|
||||||
float ld = SIN(shearY) * scaleY;
|
float ld = SIN(shearY) * scaleY;
|
||||||
self->a = za * la + zb * lc;
|
self->a = za * la + zb * lc;
|
||||||
self->b = za * lb + zb * ld;
|
self->b = za * lb + zb * ld;
|
||||||
self->c = zc * la + zd * lc;
|
self->c = zc * la + zd * lc;
|
||||||
@ -193,7 +193,7 @@ void spBone_setToSetupPose(spBone *self) {
|
|||||||
self->scaleY = self->data->scaleY;
|
self->scaleY = self->data->scaleY;
|
||||||
self->shearX = self->data->shearX;
|
self->shearX = self->data->shearX;
|
||||||
self->shearY = self->data->shearY;
|
self->shearY = self->data->shearY;
|
||||||
self->inherit = self->data->inherit;
|
self->inherit = self->data->inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
float spBone_getWorldRotationX(spBone *self) {
|
float spBone_getWorldRotationX(spBone *self) {
|
||||||
@ -225,7 +225,7 @@ void spBone_updateAppliedTransform(spBone *self) {
|
|||||||
float s, sa, sc;
|
float s, sa, sc;
|
||||||
float cosine, sine;
|
float cosine, sine;
|
||||||
|
|
||||||
float yDownScale = spBone_isYDown() ? -1 : 1;
|
float yDownScale = spBone_isYDown() ? -1 : 1;
|
||||||
|
|
||||||
spBone *parent = self->parent;
|
spBone *parent = self->parent;
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
@ -266,7 +266,7 @@ void spBone_updateAppliedTransform(spBone *self) {
|
|||||||
}
|
}
|
||||||
case SP_INHERIT_NOSCALE:
|
case SP_INHERIT_NOSCALE:
|
||||||
case SP_INHERIT_NOSCALEORREFLECTION: {
|
case SP_INHERIT_NOSCALEORREFLECTION: {
|
||||||
float r = self->rotation * DEG_RAD;
|
float r = self->rotation * DEG_RAD;
|
||||||
cosine = COS(r), sine = SIN(r);
|
cosine = COS(r), sine = SIN(r);
|
||||||
pa = (pa * cosine + pb * sine) / self->skeleton->scaleX;
|
pa = (pa * cosine + pb * sine) / self->skeleton->scaleX;
|
||||||
pc = (pc * cosine + pd * sine) / self->skeleton->scaleY * yDownScale;
|
pc = (pc * cosine + pd * sine) / self->skeleton->scaleY * yDownScale;
|
||||||
@ -321,12 +321,12 @@ void spBone_worldToLocal(spBone *self, float worldX, float worldY, float *localX
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spBone_worldToParent(spBone *self, float worldX, float worldY, float *localX, float *localY) {
|
void spBone_worldToParent(spBone *self, float worldX, float worldY, float *localX, float *localY) {
|
||||||
if (self->parent == NULL) {
|
if (self->parent == NULL) {
|
||||||
*localX = worldX;
|
*localX = worldX;
|
||||||
*localY = worldY;
|
*localY = worldY;
|
||||||
} else {
|
} else {
|
||||||
spBone_worldToLocal(self->parent, worldX, worldY, localX, localY);
|
spBone_worldToLocal(self->parent, worldX, worldY, localX, localY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spBone_localToWorld(spBone *self, float localX, float localY, float *worldX, float *worldY) {
|
void spBone_localToWorld(spBone *self, float localX, float localY, float *worldX, float *worldY) {
|
||||||
@ -336,33 +336,32 @@ void spBone_localToWorld(spBone *self, float localX, float localY, float *worldX
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spBone_parentToWorld(spBone *self, float localX, float localY, float *worldX, float *worldY) {
|
void spBone_parentToWorld(spBone *self, float localX, float localY, float *worldX, float *worldY) {
|
||||||
if (self->parent != NULL) {
|
if (self->parent != NULL) {
|
||||||
*worldX = localX;
|
*worldX = localX;
|
||||||
*worldY = localY;
|
*worldY = localY;
|
||||||
} else {
|
} else {
|
||||||
spBone_localToWorld(self->parent, localX, localY, worldX, worldY);
|
spBone_localToWorld(self->parent, localX, localY, worldX, worldY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float spBone_worldToLocalRotation(spBone *self, float worldRotation) {
|
float spBone_worldToLocalRotation(spBone *self, float worldRotation) {
|
||||||
worldRotation *= DEG_RAD;
|
worldRotation *= DEG_RAD;
|
||||||
float sine = SIN(worldRotation), cosine = COS(worldRotation);
|
float sine = SIN(worldRotation), cosine = COS(worldRotation);
|
||||||
return ATAN2DEG(self->a * sine - self->c * cosine, self->d * cosine - self->b * sine) + self->rotation - self->shearX;
|
return ATAN2DEG(self->a * sine - self->c * cosine, self->d * cosine - self->b * sine) + self->rotation - self->shearX;
|
||||||
}
|
}
|
||||||
|
|
||||||
float spBone_localToWorldRotation(spBone *self, float localRotation) {
|
float spBone_localToWorldRotation(spBone *self, float localRotation) {
|
||||||
localRotation = (localRotation - self->rotation - self->shearX) * DEG_RAD;
|
localRotation = (localRotation - self->rotation - self->shearX) * DEG_RAD;
|
||||||
float sine = SIN(localRotation), cosine = COS(localRotation);
|
float sine = SIN(localRotation), cosine = COS(localRotation);
|
||||||
return ATAN2DEG(cosine * self->c + sine * self->d, cosine * self->a + sine * self->b);
|
return ATAN2DEG(cosine * self->c + sine * self->d, cosine * self->a + sine * self->b);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void spBone_rotateWorld(spBone *self, float degrees) {
|
void spBone_rotateWorld(spBone *self, float degrees) {
|
||||||
degrees *= DEG_RAD;
|
degrees *= DEG_RAD;
|
||||||
float sine = SIN(degrees), cosine = COS(degrees);
|
float sine = SIN(degrees), cosine = COS(degrees);
|
||||||
float ra = self->a, rb = self->b;
|
float ra = self->a, rb = self->b;
|
||||||
self->a = cosine * ra - sine * self->c;
|
self->a = cosine * ra - sine * self->c;
|
||||||
self->b = cosine * rb - sine * self->d;
|
self->b = cosine * rb - sine * self->d;
|
||||||
self->c = sine * ra + cosine * self->c;
|
self->c = sine * ra + cosine * self->c;
|
||||||
self->d = sine * rb + cosine * self->d;
|
self->d = sine * rb + cosine * self->d;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,13 +38,13 @@ spBoneData *spBoneData_create(int index, const char *name, spBoneData *parent) {
|
|||||||
self->scaleX = 1;
|
self->scaleX = 1;
|
||||||
self->scaleY = 1;
|
self->scaleY = 1;
|
||||||
self->inherit = SP_INHERIT_NORMAL;
|
self->inherit = SP_INHERIT_NORMAL;
|
||||||
self->icon = NULL;
|
self->icon = NULL;
|
||||||
self->visible = -1;
|
self->visible = -1;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spBoneData_dispose(spBoneData *self) {
|
void spBoneData_dispose(spBoneData *self) {
|
||||||
FREE(self->name);
|
FREE(self->name);
|
||||||
FREE(self->icon);
|
FREE(self->icon);
|
||||||
FREE(self);
|
FREE(self);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -209,13 +209,13 @@ void spDebug_printTimeline(spTimeline *timeline) {
|
|||||||
spSequenceTimeline *t = (spSequenceTimeline *) timeline;
|
spSequenceTimeline *t = (spSequenceTimeline *) timeline;
|
||||||
_spDebug_printTimelineBase(&t->super);
|
_spDebug_printTimelineBase(&t->super);
|
||||||
}
|
}
|
||||||
case SP_TIMELINE_INHERIT: {
|
case SP_TIMELINE_INHERIT: {
|
||||||
spInheritTimeline *t = (spInheritTimeline *) timeline;
|
spInheritTimeline *t = (spInheritTimeline *) timeline;
|
||||||
_spDebug_printTimelineBase(&t->super);
|
_spDebug_printTimelineBase(&t->super);
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
_spDebug_printTimelineBase(timeline);
|
_spDebug_printTimelineBase(timeline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -72,11 +72,11 @@ void spIkConstraint_update(spIkConstraint *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spIkConstraint_setToSetupPose(spIkConstraint *self) {
|
void spIkConstraint_setToSetupPose(spIkConstraint *self) {
|
||||||
self->bendDirection = self->data->bendDirection;
|
self->bendDirection = self->data->bendDirection;
|
||||||
self->compress = self->data->compress;
|
self->compress = self->data->compress;
|
||||||
self->stretch = self->data->stretch;
|
self->stretch = self->data->stretch;
|
||||||
self->softness = self->data->softness;
|
self->softness = self->data->softness;
|
||||||
self->mix = self->data->mix;
|
self->mix = self->data->mix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spIkConstraint_apply1(spBone *bone, float targetX, float targetY, int /*boolean*/ compress, int /*boolean*/ stretch,
|
void spIkConstraint_apply1(spBone *bone, float targetX, float targetY, int /*boolean*/ compress, int /*boolean*/ stretch,
|
||||||
|
|||||||
@ -117,9 +117,9 @@ void spPathConstraint_update(spPathConstraint *self) {
|
|||||||
for (i = 0, n = spacesCount - 1; i < n; i++) {
|
for (i = 0, n = spacesCount - 1; i < n; i++) {
|
||||||
spBone *bone = bones[i];
|
spBone *bone = bones[i];
|
||||||
setupLength = bone->data->length;
|
setupLength = bone->data->length;
|
||||||
x = setupLength * bone->a;
|
x = setupLength * bone->a;
|
||||||
y = setupLength * bone->c;
|
y = setupLength * bone->c;
|
||||||
lengths[i] = SQRT(x * x + y * y);
|
lengths[i] = SQRT(x * x + y * y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 1, n = spacesCount; i < n; i++) spaces[i] = spacing;
|
for (i = 1, n = spacesCount; i < n; i++) spaces[i] = spacing;
|
||||||
@ -222,12 +222,12 @@ void spPathConstraint_update(spPathConstraint *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spPathConstraint_setToSetupPose(spPathConstraint *self) {
|
void spPathConstraint_setToSetupPose(spPathConstraint *self) {
|
||||||
spPathConstraintData *data = self->data;
|
spPathConstraintData *data = self->data;
|
||||||
self->position = data->position;
|
self->position = data->position;
|
||||||
self->spacing = data->spacing;
|
self->spacing = data->spacing;
|
||||||
self->mixRotate = data->mixRotate;
|
self->mixRotate = data->mixRotate;
|
||||||
self->mixX = data->mixX;
|
self->mixX = data->mixX;
|
||||||
self->mixY = data->mixY;
|
self->mixY = data->mixY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _addBeforePosition(float p, float *temp, int i, float *out, int o) {
|
static void _addBeforePosition(float p, float *temp, int i, float *out, int o) {
|
||||||
|
|||||||
@ -32,35 +32,35 @@
|
|||||||
#include <spine/extension.h>
|
#include <spine/extension.h>
|
||||||
|
|
||||||
spPhysicsConstraint *spPhysicsConstraint_create(spPhysicsConstraintData *data, spSkeleton *skeleton) {
|
spPhysicsConstraint *spPhysicsConstraint_create(spPhysicsConstraintData *data, spSkeleton *skeleton) {
|
||||||
spPhysicsConstraint *self = NEW(spPhysicsConstraint);
|
spPhysicsConstraint *self = NEW(spPhysicsConstraint);
|
||||||
self->data = data;
|
self->data = data;
|
||||||
self->skeleton = skeleton;
|
self->skeleton = skeleton;
|
||||||
self->bone = skeleton->bones[data->bone->index];
|
self->bone = skeleton->bones[data->bone->index];
|
||||||
self->inertia = data->inertia;
|
self->inertia = data->inertia;
|
||||||
self->strength = data->strength;
|
self->strength = data->strength;
|
||||||
self->damping = data->damping;
|
self->damping = data->damping;
|
||||||
self->massInverse = data->massInverse;
|
self->massInverse = data->massInverse;
|
||||||
self->wind = data->wind;
|
self->wind = data->wind;
|
||||||
self->gravity = data->gravity;
|
self->gravity = data->gravity;
|
||||||
self->mix = data->mix;
|
self->mix = data->mix;
|
||||||
|
|
||||||
self->reset = -1;
|
self->reset = -1;
|
||||||
self->ux = 0;
|
self->ux = 0;
|
||||||
self->uy = 0;
|
self->uy = 0;
|
||||||
self->cx = 0;
|
self->cx = 0;
|
||||||
self->tx = 0;
|
self->tx = 0;
|
||||||
self->ty = 0;
|
self->ty = 0;
|
||||||
self->xOffset = 0;
|
self->xOffset = 0;
|
||||||
self->xVelocity = 0;
|
self->xVelocity = 0;
|
||||||
self->yOffset = 0;
|
self->yOffset = 0;
|
||||||
self->yVelocity = 0;
|
self->yVelocity = 0;
|
||||||
self->rotateOffset = 0;
|
self->rotateOffset = 0;
|
||||||
self->rotateVelocity = 0;
|
self->rotateVelocity = 0;
|
||||||
self->scaleOffset = 0;
|
self->scaleOffset = 0;
|
||||||
self->scaleVelocity = 0;
|
self->scaleVelocity = 0;
|
||||||
self->active = 0;
|
self->active = 0;
|
||||||
self->remaining = 0;
|
self->remaining = 0;
|
||||||
self->lastTime = 0;
|
self->lastTime = 0;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,210 +69,210 @@ void spPhysicsConstraint_dispose(spPhysicsConstraint *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spPhysicsConstraint_reset(spPhysicsConstraint *self) {
|
void spPhysicsConstraint_reset(spPhysicsConstraint *self) {
|
||||||
self->remaining = 0;
|
self->remaining = 0;
|
||||||
self->lastTime = self->skeleton->time;
|
self->lastTime = self->skeleton->time;
|
||||||
self->reset = -1;
|
self->reset = -1;
|
||||||
self->xOffset = 0;
|
self->xOffset = 0;
|
||||||
self->xVelocity = 0;
|
self->xVelocity = 0;
|
||||||
self->yOffset = 0;
|
self->yOffset = 0;
|
||||||
self->yVelocity = 0;
|
self->yVelocity = 0;
|
||||||
self->rotateOffset = 0;
|
self->rotateOffset = 0;
|
||||||
self->rotateVelocity = 0;
|
self->rotateVelocity = 0;
|
||||||
self->scaleOffset = 0;
|
self->scaleOffset = 0;
|
||||||
self->scaleVelocity = 0;
|
self->scaleVelocity = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spPhysicsConstraint_setToSetupPose(spPhysicsConstraint *self) {
|
void spPhysicsConstraint_setToSetupPose(spPhysicsConstraint *self) {
|
||||||
self->inertia = self->data->inertia;
|
self->inertia = self->data->inertia;
|
||||||
self->strength = self->data->strength;
|
self->strength = self->data->strength;
|
||||||
self->damping = self->data->damping;
|
self->damping = self->data->damping;
|
||||||
self->massInverse = self->data->massInverse;
|
self->massInverse = self->data->massInverse;
|
||||||
self->wind = self->data->wind;
|
self->wind = self->data->wind;
|
||||||
self->gravity = self->data->gravity;
|
self->gravity = self->data->gravity;
|
||||||
self->mix = self->data->mix;
|
self->mix = self->data->mix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spPhysicsConstraint_update(spPhysicsConstraint *self, spPhysics physics) {
|
void spPhysicsConstraint_update(spPhysicsConstraint *self, spPhysics physics) {
|
||||||
float mix = self->mix;
|
float mix = self->mix;
|
||||||
if (mix == 0) return;
|
if (mix == 0) return;
|
||||||
|
|
||||||
int x = self->data->x > 0;
|
int x = self->data->x > 0;
|
||||||
int y = self->data->y > 0;
|
int y = self->data->y > 0;
|
||||||
int rotateOrShearX = self->data->rotate > 0 || self->data->shearX > 0;
|
int rotateOrShearX = self->data->rotate > 0 || self->data->shearX > 0;
|
||||||
int scaleX = self->data->scaleX > 0;
|
int scaleX = self->data->scaleX > 0;
|
||||||
|
|
||||||
spBone *bone = self->bone;
|
spBone *bone = self->bone;
|
||||||
float l = bone->data->length;
|
float l = bone->data->length;
|
||||||
|
|
||||||
switch (physics) {
|
switch (physics) {
|
||||||
case SP_PHYSICS_NONE:
|
case SP_PHYSICS_NONE:
|
||||||
return;
|
return;
|
||||||
case SP_PHYSICS_RESET:
|
case SP_PHYSICS_RESET:
|
||||||
spPhysicsConstraint_reset(self);
|
spPhysicsConstraint_reset(self);
|
||||||
// Fall through.
|
// Fall through.
|
||||||
case SP_PHYSICS_UPDATE: {
|
case SP_PHYSICS_UPDATE: {
|
||||||
float delta = MAX(self->skeleton->time - self->lastTime, 0.0f);
|
float delta = MAX(self->skeleton->time - self->lastTime, 0.0f);
|
||||||
self->remaining += delta;
|
self->remaining += delta;
|
||||||
self->lastTime = self->skeleton->time;
|
self->lastTime = self->skeleton->time;
|
||||||
|
|
||||||
float bx = bone->worldX, by = bone->worldY;
|
float bx = bone->worldX, by = bone->worldY;
|
||||||
if (self->reset) {
|
if (self->reset) {
|
||||||
self->reset = 0;
|
self->reset = 0;
|
||||||
self->ux = bx;
|
self->ux = bx;
|
||||||
self->uy = by;
|
self->uy = by;
|
||||||
} else {
|
} else {
|
||||||
float a = self->remaining, i = self->inertia, q = self->data->limit * delta, t = self->data->step, f = self->skeleton->data->referenceScale, d = -1;
|
float a = self->remaining, i = self->inertia, q = self->data->limit * delta, t = self->data->step, f = self->skeleton->data->referenceScale, d = -1;
|
||||||
if (x || y) {
|
if (x || y) {
|
||||||
if (x) {
|
if (x) {
|
||||||
float u = (self->ux - bx) * i;
|
float u = (self->ux - bx) * i;
|
||||||
self->xOffset += u > q ? q : u < -q ? -q
|
self->xOffset += u > q ? q : u < -q ? -q
|
||||||
: u;
|
: u;
|
||||||
self->ux = bx;
|
self->ux = bx;
|
||||||
}
|
}
|
||||||
if (y) {
|
if (y) {
|
||||||
float u = (self->uy - by) * i;
|
float u = (self->uy - by) * i;
|
||||||
self->yOffset += u > q ? q : u < -q ? -q
|
self->yOffset += u > q ? q : u < -q ? -q
|
||||||
: u;
|
: u;
|
||||||
self->uy = by;
|
self->uy = by;
|
||||||
}
|
}
|
||||||
if (a >= t) {
|
if (a >= t) {
|
||||||
d = POW(self->damping, 60 * t);
|
d = POW(self->damping, 60 * t);
|
||||||
float m = self->massInverse * t, e = self->strength, w = self->wind * f, g = self->gravity * f * (spBone_isYDown() ? -1 : 1);
|
float m = self->massInverse * t, e = self->strength, w = self->wind * f, g = self->gravity * f * (spBone_isYDown() ? -1 : 1);
|
||||||
do {
|
do {
|
||||||
if (x) {
|
if (x) {
|
||||||
self->xVelocity += (w - self->xOffset * e) * m;
|
self->xVelocity += (w - self->xOffset * e) * m;
|
||||||
self->xOffset += self->xVelocity * t;
|
self->xOffset += self->xVelocity * t;
|
||||||
self->xVelocity *= d;
|
self->xVelocity *= d;
|
||||||
}
|
}
|
||||||
if (y) {
|
if (y) {
|
||||||
self->yVelocity -= (g + self->yOffset * e) * m;
|
self->yVelocity -= (g + self->yOffset * e) * m;
|
||||||
self->yOffset += self->yVelocity * t;
|
self->yOffset += self->yVelocity * t;
|
||||||
self->yVelocity *= d;
|
self->yVelocity *= d;
|
||||||
}
|
}
|
||||||
a -= t;
|
a -= t;
|
||||||
} while (a >= t);
|
} while (a >= t);
|
||||||
}
|
}
|
||||||
if (x) bone->worldX += self->xOffset * mix * self->data->x;
|
if (x) bone->worldX += self->xOffset * mix * self->data->x;
|
||||||
if (y) bone->worldY += self->yOffset * mix * self->data->y;
|
if (y) bone->worldY += self->yOffset * mix * self->data->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rotateOrShearX || scaleX) {
|
if (rotateOrShearX || scaleX) {
|
||||||
float ca = ATAN2(bone->c, bone->a), c, s, mr = 0;
|
float ca = ATAN2(bone->c, bone->a), c, s, mr = 0;
|
||||||
float dx = self->cx - bone->worldX, dy = self->cy - bone->worldY;
|
float dx = self->cx - bone->worldX, dy = self->cy - bone->worldY;
|
||||||
if (dx > q)
|
if (dx > q)
|
||||||
dx = q;
|
dx = q;
|
||||||
else if (dx < -q)//
|
else if (dx < -q)//
|
||||||
dx = -q;
|
dx = -q;
|
||||||
if (dy > q)
|
if (dy > q)
|
||||||
dy = q;
|
dy = q;
|
||||||
else if (dy < -q)//
|
else if (dy < -q)//
|
||||||
dy = -q;
|
dy = -q;
|
||||||
if (rotateOrShearX) {
|
if (rotateOrShearX) {
|
||||||
mr = (self->data->rotate + self->data->shearX) * mix;
|
mr = (self->data->rotate + self->data->shearX) * mix;
|
||||||
float r = ATAN2(dy + self->ty, dx + self->tx) - ca - self->rotateOffset * mr;
|
float r = ATAN2(dy + self->ty, dx + self->tx) - ca - self->rotateOffset * mr;
|
||||||
self->rotateOffset += (r - CEIL(r * INV_PI2 - 0.5f) * PI2) * i;
|
self->rotateOffset += (r - CEIL(r * INV_PI2 - 0.5f) * PI2) * i;
|
||||||
r = self->rotateOffset * mr + ca;
|
r = self->rotateOffset * mr + ca;
|
||||||
c = COS(r);
|
c = COS(r);
|
||||||
s = SIN(r);
|
s = SIN(r);
|
||||||
if (scaleX) {
|
if (scaleX) {
|
||||||
r = l * spBone_getWorldScaleX(bone);
|
r = l * spBone_getWorldScaleX(bone);
|
||||||
if (r > 0) self->scaleOffset += (dx * c + dy * s) * i / r;
|
if (r > 0) self->scaleOffset += (dx * c + dy * s) * i / r;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c = COS(ca);
|
c = COS(ca);
|
||||||
s = SIN(ca);
|
s = SIN(ca);
|
||||||
float r = l * spBone_getWorldScaleX(bone);
|
float r = l * spBone_getWorldScaleX(bone);
|
||||||
if (r > 0) self->scaleOffset += (dx * c + dy * s) * i / r;
|
if (r > 0) self->scaleOffset += (dx * c + dy * s) * i / r;
|
||||||
}
|
}
|
||||||
a = self->remaining;
|
a = self->remaining;
|
||||||
if (a >= t) {
|
if (a >= t) {
|
||||||
if (d == -1) d = POW(self->damping, 60 * t);
|
if (d == -1) d = POW(self->damping, 60 * t);
|
||||||
float m = self->massInverse * t, e = self->strength, w = self->wind, g = self->gravity, h = l / f;
|
float m = self->massInverse * t, e = self->strength, w = self->wind, g = self->gravity, h = l / f;
|
||||||
while (-1) {
|
while (-1) {
|
||||||
a -= t;
|
a -= t;
|
||||||
if (scaleX) {
|
if (scaleX) {
|
||||||
self->scaleVelocity += (w * c - g * s - self->scaleOffset * e) * m;
|
self->scaleVelocity += (w * c - g * s - self->scaleOffset * e) * m;
|
||||||
self->scaleOffset += self->scaleVelocity * t;
|
self->scaleOffset += self->scaleVelocity * t;
|
||||||
self->scaleVelocity *= d;
|
self->scaleVelocity *= d;
|
||||||
}
|
}
|
||||||
if (rotateOrShearX) {
|
if (rotateOrShearX) {
|
||||||
self->rotateVelocity -= ((w * s + g * c) * h + self->rotateOffset * e) * m;
|
self->rotateVelocity -= ((w * s + g * c) * h + self->rotateOffset * e) * m;
|
||||||
self->rotateOffset += self->rotateVelocity * t;
|
self->rotateOffset += self->rotateVelocity * t;
|
||||||
self->rotateVelocity *= d;
|
self->rotateVelocity *= d;
|
||||||
if (a < t) break;
|
if (a < t) break;
|
||||||
float r = self->rotateOffset * mr + ca;
|
float r = self->rotateOffset * mr + ca;
|
||||||
c = COS(r);
|
c = COS(r);
|
||||||
s = SIN(r);
|
s = SIN(r);
|
||||||
} else if (a < t)//
|
} else if (a < t)//
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self->remaining = a;
|
self->remaining = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
self->cx = bone->worldX;
|
self->cx = bone->worldX;
|
||||||
self->cy = bone->worldY;
|
self->cy = bone->worldY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SP_PHYSICS_POSE: {
|
case SP_PHYSICS_POSE: {
|
||||||
if (x) bone->worldX += self->xOffset * mix * self->data->x;
|
if (x) bone->worldX += self->xOffset * mix * self->data->x;
|
||||||
if (y) bone->worldY += self->yOffset * mix * self->data->y;
|
if (y) bone->worldY += self->yOffset * mix * self->data->y;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rotateOrShearX) {
|
if (rotateOrShearX) {
|
||||||
float o = self->rotateOffset * mix, s = 0, c = 0, a = 0;
|
float o = self->rotateOffset * mix, s = 0, c = 0, a = 0;
|
||||||
if (self->data->shearX > 0) {
|
if (self->data->shearX > 0) {
|
||||||
float r = 0;
|
float r = 0;
|
||||||
if (self->data->rotate > 0) {
|
if (self->data->rotate > 0) {
|
||||||
r = o * self->data->rotate;
|
r = o * self->data->rotate;
|
||||||
s = SIN(r);
|
s = SIN(r);
|
||||||
c = COS(r);
|
c = COS(r);
|
||||||
a = bone->b;
|
a = bone->b;
|
||||||
bone->b = c * a - s * bone->d;
|
bone->b = c * a - s * bone->d;
|
||||||
bone->d = s * a + c * bone->d;
|
bone->d = s * a + c * bone->d;
|
||||||
}
|
}
|
||||||
r += o * self->data->shearX;
|
r += o * self->data->shearX;
|
||||||
s = SIN(r);
|
s = SIN(r);
|
||||||
c = COS(r);
|
c = COS(r);
|
||||||
a = bone->a;
|
a = bone->a;
|
||||||
bone->a = c * a - s * bone->c;
|
bone->a = c * a - s * bone->c;
|
||||||
bone->c = s * a + c * bone->c;
|
bone->c = s * a + c * bone->c;
|
||||||
} else {
|
} else {
|
||||||
o *= self->data->rotate;
|
o *= self->data->rotate;
|
||||||
s = SIN(o);
|
s = SIN(o);
|
||||||
c = COS(o);
|
c = COS(o);
|
||||||
a = bone->a;
|
a = bone->a;
|
||||||
bone->a = c * a - s * bone->c;
|
bone->a = c * a - s * bone->c;
|
||||||
bone->c = s * a + c * bone->c;
|
bone->c = s * a + c * bone->c;
|
||||||
a = bone->b;
|
a = bone->b;
|
||||||
bone->b = c * a - s * bone->d;
|
bone->b = c * a - s * bone->d;
|
||||||
bone->d = s * a + c * bone->d;
|
bone->d = s * a + c * bone->d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (scaleX) {
|
if (scaleX) {
|
||||||
float s = 1 + self->scaleOffset * mix * self->data->scaleX;
|
float s = 1 + self->scaleOffset * mix * self->data->scaleX;
|
||||||
bone->a *= s;
|
bone->a *= s;
|
||||||
bone->c *= s;
|
bone->c *= s;
|
||||||
}
|
}
|
||||||
if (physics != SP_PHYSICS_POSE) {
|
if (physics != SP_PHYSICS_POSE) {
|
||||||
self->tx = l * bone->a;
|
self->tx = l * bone->a;
|
||||||
self->ty = l * bone->c;
|
self->ty = l * bone->c;
|
||||||
}
|
}
|
||||||
spBone_updateAppliedTransform(bone);
|
spBone_updateAppliedTransform(bone);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spPhysicsConstraint_rotate(spPhysicsConstraint *self, float x, float y, float degrees) {
|
void spPhysicsConstraint_rotate(spPhysicsConstraint *self, float x, float y, float degrees) {
|
||||||
float r = degrees * DEG_RAD, cosine = COS(r), sine = SIN(r);
|
float r = degrees * DEG_RAD, cosine = COS(r), sine = SIN(r);
|
||||||
float dx = self->cx - x, dy = self->cy - y;
|
float dx = self->cx - x, dy = self->cy - y;
|
||||||
spPhysicsConstraint_translate(self, dx * cosine - dy * sine - dx, dx * sine + dy * cosine - dy);
|
spPhysicsConstraint_translate(self, dx * cosine - dy * sine - dx, dx * sine + dy * cosine - dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spPhysicsConstraint_translate(spPhysicsConstraint *self, float x, float y) {
|
void spPhysicsConstraint_translate(spPhysicsConstraint *self, float x, float y) {
|
||||||
self->ux -= x;
|
self->ux -= x;
|
||||||
self->uy -= y;
|
self->uy -= y;
|
||||||
self->cx -= x;
|
self->cx -= x;
|
||||||
self->cy -= y;
|
self->cy -= y;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,30 +31,30 @@
|
|||||||
#include <spine/extension.h>
|
#include <spine/extension.h>
|
||||||
|
|
||||||
spPhysicsConstraintData *spPhysicsConstraintData_create(const char *name) {
|
spPhysicsConstraintData *spPhysicsConstraintData_create(const char *name) {
|
||||||
spPhysicsConstraintData *self = NEW(spPhysicsConstraintData);
|
spPhysicsConstraintData *self = NEW(spPhysicsConstraintData);
|
||||||
MALLOC_STR(self->name, name);
|
MALLOC_STR(self->name, name);
|
||||||
self->bone = NULL;
|
self->bone = NULL;
|
||||||
self->x = 0;
|
self->x = 0;
|
||||||
self->y = 0;
|
self->y = 0;
|
||||||
self->rotate = 0;
|
self->rotate = 0;
|
||||||
self->scaleX = 0;
|
self->scaleX = 0;
|
||||||
self->shearX = 0;
|
self->shearX = 0;
|
||||||
self->limit = 0;
|
self->limit = 0;
|
||||||
self->step = 0;
|
self->step = 0;
|
||||||
self->inertia = 0;
|
self->inertia = 0;
|
||||||
self->strength = 0;
|
self->strength = 0;
|
||||||
self->damping = 0;
|
self->damping = 0;
|
||||||
self->massInverse = 0;
|
self->massInverse = 0;
|
||||||
self->wind = 0;
|
self->wind = 0;
|
||||||
self->gravity = 0;
|
self->gravity = 0;
|
||||||
self->mix = 0;
|
self->mix = 0;
|
||||||
self->inertiaGlobal = 0;
|
self->inertiaGlobal = 0;
|
||||||
self->strengthGlobal = 0;
|
self->strengthGlobal = 0;
|
||||||
self->dampingGlobal = 0;
|
self->dampingGlobal = 0;
|
||||||
self->massGlobal = 0;
|
self->massGlobal = 0;
|
||||||
self->windGlobal = 0;
|
self->windGlobal = 0;
|
||||||
self->gravityGlobal = 0;
|
self->gravityGlobal = 0;
|
||||||
self->mixGlobal = 0;
|
self->mixGlobal = 0;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -58,8 +58,8 @@ void spPointAttachment_computeWorldPosition(spPointAttachment *self, spBone *bon
|
|||||||
}
|
}
|
||||||
|
|
||||||
float spPointAttachment_computeWorldRotation(spPointAttachment *self, spBone *bone) {
|
float spPointAttachment_computeWorldRotation(spPointAttachment *self, spBone *bone) {
|
||||||
float r = self->rotation * DEG_RAD, cosine = COS(r), sine = SIN(r);
|
float r = self->rotation * DEG_RAD, cosine = COS(r), sine = SIN(r);
|
||||||
float x = cosine * bone->a + sine * bone->b;
|
float x = cosine * bone->a + sine * bone->b;
|
||||||
float y = cosine * bone->c + sine * bone->d;
|
float y = cosine * bone->c + sine * bone->d;
|
||||||
return ATAN2DEG(y, x);
|
return ATAN2DEG(y, x);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,7 +85,7 @@ spSkeleton *spSkeleton_create(spSkeletonData *data) {
|
|||||||
for (i = 0; i < self->bonesCount; ++i) {
|
for (i = 0; i < self->bonesCount; ++i) {
|
||||||
spBoneData *boneData = self->data->bones[i];
|
spBoneData *boneData = self->data->bones[i];
|
||||||
spBone *bone = self->bones[i];
|
spBone *bone = self->bones[i];
|
||||||
bone->children = MALLOC(spBone *, childrenCounts[boneData->index]);
|
bone->children = MALLOC(spBone *, childrenCounts[boneData->index]);
|
||||||
}
|
}
|
||||||
for (i = 0; i < self->bonesCount; ++i) {
|
for (i = 0; i < self->bonesCount; ++i) {
|
||||||
spBone *bone = self->bones[i];
|
spBone *bone = self->bones[i];
|
||||||
@ -132,7 +132,7 @@ spSkeleton *spSkeleton_create(spSkeletonData *data) {
|
|||||||
self->scaleX = 1;
|
self->scaleX = 1;
|
||||||
self->scaleY = 1;
|
self->scaleY = 1;
|
||||||
|
|
||||||
self->time = 0;
|
self->time = 0;
|
||||||
|
|
||||||
spSkeleton_updateCache(self);
|
spSkeleton_updateCache(self);
|
||||||
|
|
||||||
@ -342,9 +342,9 @@ static void _sortTransformConstraint(_spSkeleton *const internal, spTransformCon
|
|||||||
static void _sortPhysicsConstraint(_spSkeleton *const internal, spPhysicsConstraint *constraint) {
|
static void _sortPhysicsConstraint(_spSkeleton *const internal, spPhysicsConstraint *constraint) {
|
||||||
spBone *bone = constraint->bone;
|
spBone *bone = constraint->bone;
|
||||||
constraint->active = constraint->bone->active && (!constraint->data->skinRequired || (internal->super.skin != 0 &&
|
constraint->active = constraint->bone->active && (!constraint->data->skinRequired || (internal->super.skin != 0 &&
|
||||||
spPhysicsConstraintDataArray_contains(
|
spPhysicsConstraintDataArray_contains(
|
||||||
internal->super.skin->physicsConstraints,
|
internal->super.skin->physicsConstraints,
|
||||||
constraint->data)));
|
constraint->data)));
|
||||||
if (!constraint->active)
|
if (!constraint->active)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -367,7 +367,7 @@ void spSkeleton_updateCache(spSkeleton *self) {
|
|||||||
|
|
||||||
internal->updateCacheCapacity =
|
internal->updateCacheCapacity =
|
||||||
self->bonesCount + self->ikConstraintsCount + self->transformConstraintsCount + self->pathConstraintsCount +
|
self->bonesCount + self->ikConstraintsCount + self->transformConstraintsCount + self->pathConstraintsCount +
|
||||||
self->physicsConstraintsCount;
|
self->physicsConstraintsCount;
|
||||||
FREE(internal->updateCache);
|
FREE(internal->updateCache);
|
||||||
internal->updateCache = MALLOC(_spUpdate, internal->updateCacheCapacity);
|
internal->updateCache = MALLOC(_spUpdate, internal->updateCacheCapacity);
|
||||||
internal->updateCacheCount = 0;
|
internal->updateCacheCount = 0;
|
||||||
@ -483,7 +483,7 @@ void spSkeleton_updateWorldTransform(const spSkeleton *self, spPhysics physics)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spSkeleton_update(spSkeleton *self, float delta) {
|
void spSkeleton_update(spSkeleton *self, float delta) {
|
||||||
self->time += delta;
|
self->time += delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spSkeleton_updateWorldTransformWith(const spSkeleton *self, const spBone *parent, spPhysics physics) {
|
void spSkeleton_updateWorldTransformWith(const spSkeleton *self, const spBone *parent, spPhysics physics) {
|
||||||
|
|||||||
@ -58,53 +58,53 @@ typedef struct {
|
|||||||
} _spSkeletonBinary;
|
} _spSkeletonBinary;
|
||||||
|
|
||||||
static int string_lastIndexOf(const char *str, char needle) {
|
static int string_lastIndexOf(const char *str, char needle) {
|
||||||
if (!str) return -1;
|
if (!str) return -1;
|
||||||
int lastIndex = -1;
|
int lastIndex = -1;
|
||||||
for (int i = 0; str[i] != '\0'; i++) {
|
for (int i = 0; str[i] != '\0'; i++) {
|
||||||
if (str[i] == needle) {
|
if (str[i] == needle) {
|
||||||
lastIndex = i;
|
lastIndex = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lastIndex;
|
return lastIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *string_substring(const char *str, int start, int end) {
|
static char *string_substring(const char *str, int start, int end) {
|
||||||
if (str == NULL || start > end || start < 0) {
|
if (str == NULL || start > end || start < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = end - start;
|
int len = end - start;
|
||||||
char *substr = MALLOC(char, len + 1);
|
char *substr = MALLOC(char, len + 1);
|
||||||
if (substr == NULL) {
|
if (substr == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(substr, str + start, len);
|
strncpy(substr, str + start, len);
|
||||||
substr[len] = '\0';
|
substr[len] = '\0';
|
||||||
|
|
||||||
return substr;
|
return substr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int string_starts_with(const char *str, const char *needle) {
|
static int string_starts_with(const char *str, const char *needle) {
|
||||||
int lenStr, lenNeedle, i;
|
int lenStr, lenNeedle, i;
|
||||||
if (!str) return 0;
|
if (!str) return 0;
|
||||||
lenStr = strlen(str);
|
lenStr = strlen(str);
|
||||||
lenNeedle = strlen(needle);
|
lenNeedle = strlen(needle);
|
||||||
if (lenStr < lenNeedle) return 0;
|
if (lenStr < lenNeedle) return 0;
|
||||||
for (i = 0; i < lenNeedle; i++) {
|
for (i = 0; i < lenNeedle; i++) {
|
||||||
if (str[i] != needle[i]) return 0;
|
if (str[i] != needle[i]) return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *string_copy(const char *str) {
|
static char *string_copy(const char *str) {
|
||||||
if (str == NULL) return NULL;
|
if (str == NULL) return NULL;
|
||||||
int len = strlen(str);
|
int len = strlen(str);
|
||||||
char *tmp = malloc(len + 1);
|
char *tmp = malloc(len + 1);
|
||||||
strncpy(tmp, str, len);
|
strncpy(tmp, str, len);
|
||||||
tmp[len] = '\0';
|
tmp[len] = '\0';
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
spSkeletonBinary *spSkeletonBinary_createWithLoader(spAttachmentLoader *attachmentLoader) {
|
spSkeletonBinary *spSkeletonBinary_createWithLoader(spAttachmentLoader *attachmentLoader) {
|
||||||
@ -314,7 +314,7 @@ static void readTimeline(_dataInput *input, spTimelineArray *timelines, spCurveT
|
|||||||
time = time2;
|
time = time2;
|
||||||
value = value2;
|
value = value2;
|
||||||
}
|
}
|
||||||
spTimelineArray_add(timelines, SUPER(timeline));
|
spTimelineArray_add(timelines, SUPER(timeline));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void readTimeline2(_dataInput *input, spTimelineArray *timelines, spCurveTimeline2 *timeline, float scale) {
|
static void readTimeline2(_dataInput *input, spTimelineArray *timelines, spCurveTimeline2 *timeline, float scale) {
|
||||||
@ -610,60 +610,60 @@ static spAnimation *_spSkeletonBinary_readAnimation(spSkeletonBinary *self, cons
|
|||||||
for (ii = 0, nn = readVarint(input, 1); ii < nn; ++ii) {
|
for (ii = 0, nn = readVarint(input, 1); ii < nn; ++ii) {
|
||||||
unsigned char timelineType = readByte(input);
|
unsigned char timelineType = readByte(input);
|
||||||
int frameCount = readVarint(input, 1);
|
int frameCount = readVarint(input, 1);
|
||||||
if (timelineType == BONE_INHERIT) {
|
if (timelineType == BONE_INHERIT) {
|
||||||
spInheritTimeline *timeline = spInheritTimeline_create(frameCount, boneIndex);
|
spInheritTimeline *timeline = spInheritTimeline_create(frameCount, boneIndex);
|
||||||
for (frame = 0; frame < frameCount; frame++) {
|
for (frame = 0; frame < frameCount; frame++) {
|
||||||
float time = readFloat(input);
|
float time = readFloat(input);
|
||||||
spInherit inherit = readByte(input);
|
spInherit inherit = readByte(input);
|
||||||
spInheritTimeline_setFrame(timeline, frame, time, inherit);
|
spInheritTimeline_setFrame(timeline, frame, time, inherit);
|
||||||
}
|
}
|
||||||
spTimelineArray_add(timelines, SUPER(timeline));
|
spTimelineArray_add(timelines, SUPER(timeline));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int bezierCount = readVarint(input, 1);
|
int bezierCount = readVarint(input, 1);
|
||||||
switch (timelineType) {
|
switch (timelineType) {
|
||||||
case BONE_ROTATE:
|
case BONE_ROTATE:
|
||||||
readTimeline(input, timelines, SUPER(spRotateTimeline_create(frameCount, bezierCount, boneIndex)),
|
readTimeline(input, timelines, SUPER(spRotateTimeline_create(frameCount, bezierCount, boneIndex)),
|
||||||
1);
|
1);
|
||||||
break;
|
break;
|
||||||
case BONE_TRANSLATE:
|
case BONE_TRANSLATE:
|
||||||
readTimeline2(input,timelines,
|
readTimeline2(input, timelines,
|
||||||
SUPER(spTranslateTimeline_create(frameCount, bezierCount, boneIndex)),
|
SUPER(spTranslateTimeline_create(frameCount, bezierCount, boneIndex)),
|
||||||
scale);
|
scale);
|
||||||
break;
|
break;
|
||||||
case BONE_TRANSLATEX:
|
case BONE_TRANSLATEX:
|
||||||
readTimeline(input, timelines,
|
readTimeline(input, timelines,
|
||||||
SUPER(spTranslateXTimeline_create(frameCount, bezierCount, boneIndex)),
|
SUPER(spTranslateXTimeline_create(frameCount, bezierCount, boneIndex)),
|
||||||
scale);
|
scale);
|
||||||
break;
|
break;
|
||||||
case BONE_TRANSLATEY:
|
case BONE_TRANSLATEY:
|
||||||
readTimeline(input, timelines,
|
readTimeline(input, timelines,
|
||||||
SUPER(spTranslateYTimeline_create(frameCount, bezierCount, boneIndex)),
|
SUPER(spTranslateYTimeline_create(frameCount, bezierCount, boneIndex)),
|
||||||
scale);
|
scale);
|
||||||
break;
|
break;
|
||||||
case BONE_SCALE:
|
case BONE_SCALE:
|
||||||
readTimeline2(input, timelines, SUPER(spScaleTimeline_create(frameCount, bezierCount, boneIndex)),
|
readTimeline2(input, timelines, SUPER(spScaleTimeline_create(frameCount, bezierCount, boneIndex)),
|
||||||
1);
|
1);
|
||||||
break;
|
break;
|
||||||
case BONE_SCALEX:
|
case BONE_SCALEX:
|
||||||
readTimeline(input, timelines, SUPER(spScaleXTimeline_create(frameCount, bezierCount, boneIndex)),
|
readTimeline(input, timelines, SUPER(spScaleXTimeline_create(frameCount, bezierCount, boneIndex)),
|
||||||
1);
|
1);
|
||||||
break;
|
break;
|
||||||
case BONE_SCALEY:
|
case BONE_SCALEY:
|
||||||
readTimeline(input, timelines, SUPER(spScaleYTimeline_create(frameCount, bezierCount, boneIndex)),
|
readTimeline(input, timelines, SUPER(spScaleYTimeline_create(frameCount, bezierCount, boneIndex)),
|
||||||
1);
|
1);
|
||||||
break;
|
break;
|
||||||
case BONE_SHEAR:
|
case BONE_SHEAR:
|
||||||
readTimeline2(input, timelines, SUPER(spShearTimeline_create(frameCount, bezierCount, boneIndex)),
|
readTimeline2(input, timelines, SUPER(spShearTimeline_create(frameCount, bezierCount, boneIndex)),
|
||||||
1);
|
1);
|
||||||
break;
|
break;
|
||||||
case BONE_SHEARX:
|
case BONE_SHEARX:
|
||||||
readTimeline(input, timelines, SUPER(spShearXTimeline_create(frameCount, bezierCount, boneIndex)),
|
readTimeline(input, timelines, SUPER(spShearXTimeline_create(frameCount, bezierCount, boneIndex)),
|
||||||
1);
|
1);
|
||||||
break;
|
break;
|
||||||
case BONE_SHEARY:
|
case BONE_SHEARY:
|
||||||
readTimeline(input, timelines, SUPER(spShearYTimeline_create(frameCount, bezierCount, boneIndex)),
|
readTimeline(input, timelines, SUPER(spShearYTimeline_create(frameCount, bezierCount, boneIndex)),
|
||||||
1);
|
1);
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
for (iii = 0; iii < timelines->size; ++iii)
|
for (iii = 0; iii < timelines->size; ++iii)
|
||||||
@ -684,20 +684,20 @@ static spAnimation *_spSkeletonBinary_readAnimation(spSkeletonBinary *self, cons
|
|||||||
int frameLast = frameCount - 1;
|
int frameLast = frameCount - 1;
|
||||||
int bezierCount = readVarint(input, 1);
|
int bezierCount = readVarint(input, 1);
|
||||||
spIkConstraintTimeline *timeline = spIkConstraintTimeline_create(frameCount, bezierCount, index);
|
spIkConstraintTimeline *timeline = spIkConstraintTimeline_create(frameCount, bezierCount, index);
|
||||||
int flags = readByte(input);
|
int flags = readByte(input);
|
||||||
float time = readFloat(input), mix = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0;
|
float time = readFloat(input), mix = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0;
|
||||||
float softness = (flags & 4) != 0 ? readFloat(input) * scale : 0;
|
float softness = (flags & 4) != 0 ? readFloat(input) * scale : 0;
|
||||||
for (frame = 0, bezier = 0;; frame++) {
|
for (frame = 0, bezier = 0;; frame++) {
|
||||||
spIkConstraintTimeline_setFrame(timeline, frame, time, mix, softness, (flags & 8) != 0 ? 1 : -1, (flags & 16) != 0, (flags & 32) != 0);
|
spIkConstraintTimeline_setFrame(timeline, frame, time, mix, softness, (flags & 8) != 0 ? 1 : -1, (flags & 16) != 0, (flags & 32) != 0);
|
||||||
if (frame == frameLast) break;
|
if (frame == frameLast) break;
|
||||||
flags = readByte(input);
|
flags = readByte(input);
|
||||||
float time2 = readFloat(input), mix2 = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0;
|
float time2 = readFloat(input), mix2 = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0;
|
||||||
float softness2 = (flags & 4) != 0 ? readFloat(input) * scale : 0;
|
float softness2 = (flags & 4) != 0 ? readFloat(input) * scale : 0;
|
||||||
if ((flags & 64) != 0)
|
if ((flags & 64) != 0)
|
||||||
spCurveTimeline_setStepped(SUPER(timeline), frame);
|
spCurveTimeline_setStepped(SUPER(timeline), frame);
|
||||||
else if ((flags & 128) != 0) {
|
else if ((flags & 128) != 0) {
|
||||||
setBezier(input, SUPER(SUPER(timeline)), bezier++, frame, 0, time, time2, mix, mix2, 1);
|
setBezier(input, SUPER(SUPER(timeline)), bezier++, frame, 0, time, time2, mix, mix2, 1);
|
||||||
setBezier(input, SUPER(SUPER(timeline)), bezier++, frame, 1, time, time2, softness, softness2, scale);
|
setBezier(input, SUPER(SUPER(timeline)), bezier++, frame, 1, time, time2, softness, softness2, scale);
|
||||||
}
|
}
|
||||||
time = time2;
|
time = time2;
|
||||||
mix = mix2;
|
mix = mix2;
|
||||||
@ -766,19 +766,19 @@ static spAnimation *_spSkeletonBinary_readAnimation(spSkeletonBinary *self, cons
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case PATH_POSITION: {
|
case PATH_POSITION: {
|
||||||
readTimeline(input, timelines, SUPER(spPathConstraintPositionTimeline_create(frameCount, bezierCount, index)),
|
readTimeline(input, timelines, SUPER(spPathConstraintPositionTimeline_create(frameCount, bezierCount, index)),
|
||||||
data->positionMode == SP_POSITION_MODE_FIXED ? scale
|
data->positionMode == SP_POSITION_MODE_FIXED ? scale
|
||||||
: 1);
|
: 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PATH_SPACING: {
|
case PATH_SPACING: {
|
||||||
readTimeline(input, timelines,
|
readTimeline(input, timelines,
|
||||||
SUPER(spPathConstraintSpacingTimeline_create(frameCount,
|
SUPER(spPathConstraintSpacingTimeline_create(frameCount,
|
||||||
bezierCount,
|
bezierCount,
|
||||||
index)),
|
index)),
|
||||||
data->spacingMode == SP_SPACING_MODE_LENGTH ||
|
data->spacingMode == SP_SPACING_MODE_LENGTH ||
|
||||||
data->spacingMode == SP_SPACING_MODE_FIXED
|
data->spacingMode == SP_SPACING_MODE_FIXED
|
||||||
? scale
|
? scale
|
||||||
: 1);
|
: 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PATH_MIX: {
|
case PATH_MIX: {
|
||||||
@ -821,43 +821,43 @@ static spAnimation *_spSkeletonBinary_readAnimation(spSkeletonBinary *self, cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0, n = readVarint(input, 1); i < n; i++) {
|
for (i = 0, n = readVarint(input, 1); i < n; i++) {
|
||||||
int index = readVarint(input, 1) - 1;
|
int index = readVarint(input, 1) - 1;
|
||||||
for (ii = 0, nn = readVarint(input, 1); ii < nn; ii++) {
|
for (ii = 0, nn = readVarint(input, 1); ii < nn; ii++) {
|
||||||
int type = readByte(input);
|
int type = readByte(input);
|
||||||
int frameCount = readVarint(input, 1);
|
int frameCount = readVarint(input, 1);
|
||||||
if (type == PHYSICS_RESET) {
|
if (type == PHYSICS_RESET) {
|
||||||
spPhysicsConstraintResetTimeline *timeline = spPhysicsConstraintResetTimeline_create(frameCount, index);
|
spPhysicsConstraintResetTimeline *timeline = spPhysicsConstraintResetTimeline_create(frameCount, index);
|
||||||
for (frame = 0; frame < frameCount; frame++)
|
for (frame = 0; frame < frameCount; frame++)
|
||||||
spPhysicsConstraintResetTimeline_setFrame(timeline, frame, readFloat(input));
|
spPhysicsConstraintResetTimeline_setFrame(timeline, frame, readFloat(input));
|
||||||
spTimelineArray_add(timelines, SUPER(timeline));
|
spTimelineArray_add(timelines, SUPER(timeline));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int bezierCount = readVarint(input, 1);
|
int bezierCount = readVarint(input, 1);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PHYSICS_INERTIA:
|
case PHYSICS_INERTIA:
|
||||||
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA)), 1);
|
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA)), 1);
|
||||||
break;
|
break;
|
||||||
case PHYSICS_STRENGTH:
|
case PHYSICS_STRENGTH:
|
||||||
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH)), 1);
|
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH)), 1);
|
||||||
break;
|
break;
|
||||||
case PHYSICS_DAMPING:
|
case PHYSICS_DAMPING:
|
||||||
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING)), 1);
|
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING)), 1);
|
||||||
break;
|
break;
|
||||||
case PHYSICS_MASS:
|
case PHYSICS_MASS:
|
||||||
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_MASS)), 1);
|
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_MASS)), 1);
|
||||||
break;
|
break;
|
||||||
case PHYSICS_WIND:
|
case PHYSICS_WIND:
|
||||||
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_WIND)), 1);
|
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_WIND)), 1);
|
||||||
break;
|
break;
|
||||||
case PHYSICS_GRAVITY:
|
case PHYSICS_GRAVITY:
|
||||||
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY)), 1);
|
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY)), 1);
|
||||||
break;
|
break;
|
||||||
case PHYSICS_MIX:
|
case PHYSICS_MIX:
|
||||||
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_MIX)), 1);
|
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_MIX)), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Attachment timelines. */
|
/* Attachment timelines. */
|
||||||
for (i = 0, n = readVarint(input, 1); i < n; ++i) {
|
for (i = 0, n = readVarint(input, 1); i < n; ++i) {
|
||||||
@ -1000,13 +1000,13 @@ static spAnimation *_spSkeletonBinary_readAnimation(spSkeletonBinary *self, cons
|
|||||||
spEvent *event = spEvent_create(time, eventData);
|
spEvent *event = spEvent_create(time, eventData);
|
||||||
event->intValue = readVarint(input, 0);
|
event->intValue = readVarint(input, 0);
|
||||||
event->floatValue = readFloat(input);
|
event->floatValue = readFloat(input);
|
||||||
const char *event_stringValue = readString(input);
|
const char *event_stringValue = readString(input);
|
||||||
if (event_stringValue == NULL) {
|
if (event_stringValue == NULL) {
|
||||||
event->stringValue = string_copy(eventData->stringValue);
|
event->stringValue = string_copy(eventData->stringValue);
|
||||||
} else {
|
} else {
|
||||||
event->stringValue = string_copy(event_stringValue);
|
event->stringValue = string_copy(event_stringValue);
|
||||||
FREE(event_stringValue);
|
FREE(event_stringValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventData->audioPath) {
|
if (eventData->audioPath) {
|
||||||
event->volume = readFloat(input);
|
event->volume = readFloat(input);
|
||||||
@ -1046,81 +1046,81 @@ static unsigned short *_readShortArray(_dataInput *input, int n) {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _readVertices(_dataInput *input, float **vertices, int *verticesLength, int **bones, int *bonesCount, int/*bool*/ weighted, float scale) {
|
static int _readVertices(_dataInput *input, float **vertices, int *verticesLength, int **bones, int *bonesCount, int /*bool*/ weighted, float scale) {
|
||||||
int vertexCount = readVarint(input, 1);
|
int vertexCount = readVarint(input, 1);
|
||||||
*verticesLength = vertexCount << 1;
|
*verticesLength = vertexCount << 1;
|
||||||
if (!weighted) {
|
if (!weighted) {
|
||||||
*vertices = _readFloatArray(input, *verticesLength, scale);
|
*vertices = _readFloatArray(input, *verticesLength, scale);
|
||||||
*bones = NULL;
|
*bones = NULL;
|
||||||
*bonesCount = 0;
|
*bonesCount = 0;
|
||||||
return *verticesLength;
|
return *verticesLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
float *v = MALLOC(float, (*verticesLength) * 3 * 3);
|
float *v = MALLOC(float, (*verticesLength) * 3 * 3);
|
||||||
int *b = MALLOC(int, (*verticesLength) * 3);
|
int *b = MALLOC(int, (*verticesLength) * 3);
|
||||||
int boneIdx = 0;
|
int boneIdx = 0;
|
||||||
int vertexIdx = 0;
|
int vertexIdx = 0;
|
||||||
for (int i = 0; i < vertexCount; ++i) {
|
for (int i = 0; i < vertexCount; ++i) {
|
||||||
int boneCount = readVarint(input, 1);
|
int boneCount = readVarint(input, 1);
|
||||||
b[boneIdx++] = boneCount;
|
b[boneIdx++] = boneCount;
|
||||||
for (int ii = 0; ii < boneCount; ++ii) {
|
for (int ii = 0; ii < boneCount; ++ii) {
|
||||||
b[boneIdx++] = readVarint(input, 1);
|
b[boneIdx++] = readVarint(input, 1);
|
||||||
v[vertexIdx++] = readFloat(input) * scale;
|
v[vertexIdx++] = readFloat(input) * scale;
|
||||||
v[vertexIdx++] = readFloat(input) * scale;
|
v[vertexIdx++] = readFloat(input) * scale;
|
||||||
v[vertexIdx++] = readFloat(input);
|
v[vertexIdx++] = readFloat(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*vertices = v;
|
*vertices = v;
|
||||||
*bones = b;
|
*bones = b;
|
||||||
*bonesCount = boneIdx;
|
*bonesCount = boneIdx;
|
||||||
*verticesLength = vertexIdx;
|
*verticesLength = vertexIdx;
|
||||||
return vertexCount << 1;
|
return vertexCount << 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
spAttachment *spSkeletonBinary_readAttachment(spSkeletonBinary *self, _dataInput *input,
|
spAttachment *spSkeletonBinary_readAttachment(spSkeletonBinary *self, _dataInput *input,
|
||||||
spSkin *skin, int slotIndex, const char *attachmentName,
|
spSkin *skin, int slotIndex, const char *attachmentName,
|
||||||
spSkeletonData *skeletonData, int /*bool*/ nonessential) {
|
spSkeletonData *skeletonData, int /*bool*/ nonessential) {
|
||||||
int flags = readByte(input);
|
int flags = readByte(input);
|
||||||
const char *name = (flags & 8) != 0 ? readStringRef(input, skeletonData) : attachmentName;
|
const char *name = (flags & 8) != 0 ? readStringRef(input, skeletonData) : attachmentName;
|
||||||
spAttachmentType type = (flags & 0x7);
|
spAttachmentType type = (flags & 0x7);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SP_ATTACHMENT_REGION: {
|
case SP_ATTACHMENT_REGION: {
|
||||||
char *path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : (char*)name;
|
char *path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : (char *) name;
|
||||||
path = string_copy(path);
|
path = string_copy(path);
|
||||||
spColor color;
|
spColor color;
|
||||||
spColor_setFromFloats(&color, 1, 1, 1, 1);
|
spColor_setFromFloats(&color, 1, 1, 1, 1);
|
||||||
if ((flags & 32) != 0) readColor(input, &color.r, &color.g, &color.b, &color.a);
|
if ((flags & 32) != 0) readColor(input, &color.r, &color.g, &color.b, &color.a);
|
||||||
spSequence *sequence = (flags & 64) != 0 ? readSequence(input) : NULL;
|
spSequence *sequence = (flags & 64) != 0 ? readSequence(input) : NULL;
|
||||||
float rotation = (flags & 128) != 0 ? readFloat(input) : 0;
|
float rotation = (flags & 128) != 0 ? readFloat(input) : 0;
|
||||||
float x = readFloat(input) * self->scale;
|
float x = readFloat(input) * self->scale;
|
||||||
float y = readFloat(input) * self->scale;
|
float y = readFloat(input) * self->scale;
|
||||||
float scaleX = readFloat(input);
|
float scaleX = readFloat(input);
|
||||||
float scaleY = readFloat(input);
|
float scaleY = readFloat(input);
|
||||||
float width = readFloat(input) * self->scale;
|
float width = readFloat(input) * self->scale;
|
||||||
float height = readFloat(input) * self->scale;
|
float height = readFloat(input) * self->scale;
|
||||||
spRegionAttachment *region = SUB_CAST(spRegionAttachment, spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name,
|
spRegionAttachment *region = SUB_CAST(spRegionAttachment, spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name,
|
||||||
path, sequence));
|
path, sequence));
|
||||||
region->path = path;
|
region->path = path;
|
||||||
region->rotation = rotation;
|
region->rotation = rotation;
|
||||||
region->x = x;
|
region->x = x;
|
||||||
region->y = y;
|
region->y = y;
|
||||||
region->scaleX = scaleX;
|
region->scaleX = scaleX;
|
||||||
region->scaleY = scaleY;
|
region->scaleY = scaleY;
|
||||||
region->width = width;
|
region->width = width;
|
||||||
region->height = height;
|
region->height = height;
|
||||||
spColor_setFromColor(®ion->color, &color);
|
spColor_setFromColor(®ion->color, &color);
|
||||||
region->sequence = sequence;
|
region->sequence = sequence;
|
||||||
if (sequence == NULL) spRegionAttachment_updateRegion(region);
|
if (sequence == NULL) spRegionAttachment_updateRegion(region);
|
||||||
spAttachmentLoader_configureAttachment(self->attachmentLoader, SUPER(region));
|
spAttachmentLoader_configureAttachment(self->attachmentLoader, SUPER(region));
|
||||||
return SUPER(region);
|
return SUPER(region);
|
||||||
}
|
}
|
||||||
case SP_ATTACHMENT_BOUNDING_BOX: {
|
case SP_ATTACHMENT_BOUNDING_BOX: {
|
||||||
spBoundingBoxAttachment *box = SUB_CAST(spBoundingBoxAttachment, spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0,
|
spBoundingBoxAttachment *box = SUB_CAST(spBoundingBoxAttachment, spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0,
|
||||||
NULL));
|
NULL));
|
||||||
if (!box) return NULL;
|
if (!box) return NULL;
|
||||||
_readVertices(input, &box->super.vertices, &box->super.verticesCount, &box->super.bones, &box->super.bonesCount, (flags & 16) != 0, self->scale);
|
_readVertices(input, &box->super.vertices, &box->super.verticesCount, &box->super.bones, &box->super.bonesCount, (flags & 16) != 0, self->scale);
|
||||||
box->super.worldVerticesLength = box->super.verticesCount;
|
box->super.worldVerticesLength = box->super.verticesCount;
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
readColor(input, &box->color.r, &box->color.g, &box->color.b, &box->color.a);
|
readColor(input, &box->color.r, &box->color.g, &box->color.b, &box->color.a);
|
||||||
}
|
}
|
||||||
@ -1128,96 +1128,96 @@ spAttachment *spSkeletonBinary_readAttachment(spSkeletonBinary *self, _dataInput
|
|||||||
return SUPER(SUPER(box));
|
return SUPER(SUPER(box));
|
||||||
}
|
}
|
||||||
case SP_ATTACHMENT_MESH: {
|
case SP_ATTACHMENT_MESH: {
|
||||||
float *uvs = NULL;
|
float *uvs = NULL;
|
||||||
int uvsCount = 0;
|
int uvsCount = 0;
|
||||||
unsigned short *triangles = NULL;
|
unsigned short *triangles = NULL;
|
||||||
int trianglesCount = 0;
|
int trianglesCount = 0;
|
||||||
float *vertices = NULL;
|
float *vertices = NULL;
|
||||||
int verticesCount = 0;
|
int verticesCount = 0;
|
||||||
int *bones = NULL;
|
int *bones = NULL;
|
||||||
int bonesCount = 0;
|
int bonesCount = 0;
|
||||||
int hullLength = 0;
|
int hullLength = 0;
|
||||||
float width = 0;
|
float width = 0;
|
||||||
float height = 0;
|
float height = 0;
|
||||||
unsigned short *edges = NULL;
|
unsigned short *edges = NULL;
|
||||||
int edgesCount = 0;
|
int edgesCount = 0;
|
||||||
|
|
||||||
char* path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : (char*)name;
|
char *path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : (char *) name;
|
||||||
path = string_copy(path);
|
path = string_copy(path);
|
||||||
spColor color;
|
spColor color;
|
||||||
spColor_setFromFloats(&color, 1, 1, 1, 1);
|
spColor_setFromFloats(&color, 1, 1, 1, 1);
|
||||||
if ((flags & 32) != 0) readColor(input, &color.r, &color.g, &color.b, &color.a);
|
if ((flags & 32) != 0) readColor(input, &color.r, &color.g, &color.b, &color.a);
|
||||||
spSequence *sequence = (flags & 64) != 0 ? readSequence(input) : NULL;
|
spSequence *sequence = (flags & 64) != 0 ? readSequence(input) : NULL;
|
||||||
hullLength = readVarint(input, 1);
|
hullLength = readVarint(input, 1);
|
||||||
int verticesLength = _readVertices(input, &vertices, &verticesCount, &bones, &bonesCount, (flags & 128) != 0, self->scale);
|
int verticesLength = _readVertices(input, &vertices, &verticesCount, &bones, &bonesCount, (flags & 128) != 0, self->scale);
|
||||||
uvsCount = verticesLength;
|
uvsCount = verticesLength;
|
||||||
uvs = _readFloatArray(input, uvsCount, 1);
|
uvs = _readFloatArray(input, uvsCount, 1);
|
||||||
trianglesCount = (verticesLength - hullLength - 2) * 3;
|
trianglesCount = (verticesLength - hullLength - 2) * 3;
|
||||||
triangles = _readShortArray(input, trianglesCount);
|
triangles = _readShortArray(input, trianglesCount);
|
||||||
|
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
edgesCount = readVarint(input, 1);
|
edgesCount = readVarint(input, 1);
|
||||||
edges = _readShortArray(input, edgesCount);
|
edges = _readShortArray(input, edgesCount);
|
||||||
width = readFloat(input);
|
width = readFloat(input);
|
||||||
height = readFloat(input);
|
height = readFloat(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path, sequence);
|
spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path, sequence);
|
||||||
if (!attachment) return NULL;
|
if (!attachment) return NULL;
|
||||||
spMeshAttachment *mesh = SUB_CAST(spMeshAttachment, attachment);
|
spMeshAttachment *mesh = SUB_CAST(spMeshAttachment, attachment);
|
||||||
mesh->path = path;
|
mesh->path = path;
|
||||||
spColor_setFromColor(&mesh->color, &color);
|
spColor_setFromColor(&mesh->color, &color);
|
||||||
mesh->regionUVs = uvs;
|
mesh->regionUVs = uvs;
|
||||||
mesh->triangles = triangles;
|
mesh->triangles = triangles;
|
||||||
mesh->trianglesCount = trianglesCount;
|
mesh->trianglesCount = trianglesCount;
|
||||||
mesh->super.vertices = vertices;
|
mesh->super.vertices = vertices;
|
||||||
mesh->super.verticesCount = verticesCount;
|
mesh->super.verticesCount = verticesCount;
|
||||||
mesh->super.bones = bones;
|
mesh->super.bones = bones;
|
||||||
mesh->super.bonesCount = bonesCount;
|
mesh->super.bonesCount = bonesCount;
|
||||||
mesh->super.worldVerticesLength = verticesLength;
|
mesh->super.worldVerticesLength = verticesLength;
|
||||||
mesh->hullLength = hullLength;
|
mesh->hullLength = hullLength;
|
||||||
mesh->edges = edges;
|
mesh->edges = edges;
|
||||||
mesh->edgesCount = edgesCount;
|
mesh->edgesCount = edgesCount;
|
||||||
mesh->width = width;
|
mesh->width = width;
|
||||||
mesh->height = height;
|
mesh->height = height;
|
||||||
mesh->sequence = sequence;
|
mesh->sequence = sequence;
|
||||||
if (sequence == NULL) spMeshAttachment_updateRegion(mesh);
|
if (sequence == NULL) spMeshAttachment_updateRegion(mesh);
|
||||||
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
|
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
|
||||||
return attachment;
|
return attachment;
|
||||||
}
|
}
|
||||||
case SP_ATTACHMENT_LINKED_MESH: {
|
case SP_ATTACHMENT_LINKED_MESH: {
|
||||||
char *path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : (char*)name;
|
char *path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : (char *) name;
|
||||||
path = string_copy(path);
|
path = string_copy(path);
|
||||||
spColor color;
|
spColor color;
|
||||||
spColor_setFromFloats(&color, 1, 1, 1, 1);
|
spColor_setFromFloats(&color, 1, 1, 1, 1);
|
||||||
if ((flags & 32) != 0) readColor(input, &color.r, &color.g, &color.b, &color.a);
|
if ((flags & 32) != 0) readColor(input, &color.r, &color.g, &color.b, &color.a);
|
||||||
spSequence *sequence = (flags & 64) != 0 ? readSequence(input) : NULL;
|
spSequence *sequence = (flags & 64) != 0 ? readSequence(input) : NULL;
|
||||||
int/*bool*/ inheritTimelines = (flags & 128) != 0;
|
int /*bool*/ inheritTimelines = (flags & 128) != 0;
|
||||||
int skinIndex = readVarint(input, 1);
|
int skinIndex = readVarint(input, 1);
|
||||||
char *parent = readStringRef(input, skeletonData);
|
char *parent = readStringRef(input, skeletonData);
|
||||||
float width = 0, height = 0;
|
float width = 0, height = 0;
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
width = readFloat(input) * self->scale;
|
width = readFloat(input) * self->scale;
|
||||||
height = readFloat(input) * self->scale;
|
height = readFloat(input) * self->scale;
|
||||||
}
|
}
|
||||||
spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path, sequence);
|
spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path, sequence);
|
||||||
spMeshAttachment *mesh = NULL;
|
spMeshAttachment *mesh = NULL;
|
||||||
if (!attachment)
|
if (!attachment)
|
||||||
return NULL;
|
return NULL;
|
||||||
mesh = SUB_CAST(spMeshAttachment, attachment);
|
mesh = SUB_CAST(spMeshAttachment, attachment);
|
||||||
mesh->path = (char*)path;
|
mesh->path = (char *) path;
|
||||||
if (mesh->path) {
|
if (mesh->path) {
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
MALLOC_STR(tmp, mesh->path);
|
MALLOC_STR(tmp, mesh->path);
|
||||||
mesh->path = tmp;
|
mesh->path = tmp;
|
||||||
}
|
}
|
||||||
spColor_setFromColor(&mesh->color, &color);
|
spColor_setFromColor(&mesh->color, &color);
|
||||||
mesh->sequence = sequence;
|
mesh->sequence = sequence;
|
||||||
mesh->width = width;
|
mesh->width = width;
|
||||||
mesh->height = height;
|
mesh->height = height;
|
||||||
_spSkeletonBinary_addLinkedMesh(self, mesh, skinIndex, slotIndex, parent, inheritTimelines);
|
_spSkeletonBinary_addLinkedMesh(self, mesh, skinIndex, slotIndex, parent, inheritTimelines);
|
||||||
return attachment;
|
return attachment;
|
||||||
}
|
}
|
||||||
case SP_ATTACHMENT_PATH: {
|
case SP_ATTACHMENT_PATH: {
|
||||||
spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0,
|
spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0,
|
||||||
@ -1226,11 +1226,11 @@ spAttachment *spSkeletonBinary_readAttachment(spSkeletonBinary *self, _dataInput
|
|||||||
if (!attachment)
|
if (!attachment)
|
||||||
return NULL;
|
return NULL;
|
||||||
path = SUB_CAST(spPathAttachment, attachment);
|
path = SUB_CAST(spPathAttachment, attachment);
|
||||||
path->closed = (flags & 16) != 0;
|
path->closed = (flags & 16) != 0;
|
||||||
path->constantSpeed = (flags & 32) != 0;
|
path->constantSpeed = (flags & 32) != 0;
|
||||||
int verticesLength = _readVertices(input, &path->super.vertices, &path->super.verticesCount, &path->super.bones, &path->super.bonesCount, (flags & 64) != 0, self->scale);
|
int verticesLength = _readVertices(input, &path->super.vertices, &path->super.verticesCount, &path->super.bones, &path->super.bonesCount, (flags & 64) != 0, self->scale);
|
||||||
path->super.worldVerticesLength = verticesLength;
|
path->super.worldVerticesLength = verticesLength;
|
||||||
path->lengthsLength = verticesLength / 6;
|
path->lengthsLength = verticesLength / 6;
|
||||||
path->lengths = MALLOC(float, path->lengthsLength);
|
path->lengths = MALLOC(float, path->lengthsLength);
|
||||||
for (int i = 0; i < path->lengthsLength; ++i) {
|
for (int i = 0; i < path->lengthsLength; ++i) {
|
||||||
path->lengths[i] = readFloat(input) * self->scale;
|
path->lengths[i] = readFloat(input) * self->scale;
|
||||||
@ -1266,8 +1266,8 @@ spAttachment *spSkeletonBinary_readAttachment(spSkeletonBinary *self, _dataInput
|
|||||||
if (!attachment)
|
if (!attachment)
|
||||||
return NULL;
|
return NULL;
|
||||||
clip = SUB_CAST(spClippingAttachment, attachment);
|
clip = SUB_CAST(spClippingAttachment, attachment);
|
||||||
int verticesLength = _readVertices(input, &clip->super.vertices, &clip->super.verticesCount, &clip->super.bones, &clip->super.bonesCount, (flags & 16) != 0, self->scale);
|
int verticesLength = _readVertices(input, &clip->super.vertices, &clip->super.verticesCount, &clip->super.bones, &clip->super.bonesCount, (flags & 16) != 0, self->scale);
|
||||||
clip->super.worldVerticesLength = verticesLength;
|
clip->super.worldVerticesLength = verticesLength;
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
readColor(input, &clip->color.r, &clip->color.g, &clip->color.b, &clip->color.a);
|
readColor(input, &clip->color.r, &clip->color.g, &clip->color.b, &clip->color.a);
|
||||||
}
|
}
|
||||||
@ -1290,10 +1290,10 @@ spSkin *spSkeletonBinary_readSkin(spSkeletonBinary *self, _dataInput *input, int
|
|||||||
if (slotCount == 0) return NULL;
|
if (slotCount == 0) return NULL;
|
||||||
skin = spSkin_create("default");
|
skin = spSkin_create("default");
|
||||||
} else {
|
} else {
|
||||||
char *name = readString(input);
|
char *name = readString(input);
|
||||||
skin = spSkin_create(name);
|
skin = spSkin_create(name);
|
||||||
FREE(name);
|
FREE(name);
|
||||||
if (nonessential) readColor(input, &skin->color.r, &skin->color.g, &skin->color.b, &skin->color.a);
|
if (nonessential) readColor(input, &skin->color.r, &skin->color.g, &skin->color.b, &skin->color.a);
|
||||||
for (i = 0, n = readVarint(input, 1); i < n; i++)
|
for (i = 0, n = readVarint(input, 1); i < n; i++)
|
||||||
spBoneDataArray_add(skin->bones, skeletonData->bones[readVarint(input, 1)]);
|
spBoneDataArray_add(skin->bones, skeletonData->bones[readVarint(input, 1)]);
|
||||||
|
|
||||||
@ -1307,10 +1307,10 @@ spSkin *spSkeletonBinary_readSkin(spSkeletonBinary *self, _dataInput *input, int
|
|||||||
for (i = 0, n = readVarint(input, 1); i < n; i++)
|
for (i = 0, n = readVarint(input, 1); i < n; i++)
|
||||||
spPathConstraintDataArray_add(skin->pathConstraints, skeletonData->pathConstraints[readVarint(input, 1)]);
|
spPathConstraintDataArray_add(skin->pathConstraints, skeletonData->pathConstraints[readVarint(input, 1)]);
|
||||||
|
|
||||||
for (i = 0, n = readVarint(input, 1); i < n; i++)
|
for (i = 0, n = readVarint(input, 1); i < n; i++)
|
||||||
spPhysicsConstraintDataArray_add(skin->physicsConstraints, skeletonData->physicsConstraints[readVarint(input, 1)]);
|
spPhysicsConstraintDataArray_add(skin->physicsConstraints, skeletonData->physicsConstraints[readVarint(input, 1)]);
|
||||||
|
|
||||||
slotCount = readVarint(input, 1);
|
slotCount = readVarint(input, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < slotCount; ++i) {
|
for (i = 0; i < slotCount; ++i) {
|
||||||
@ -1380,7 +1380,7 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
|
|||||||
skeletonData->y = readFloat(input);
|
skeletonData->y = readFloat(input);
|
||||||
skeletonData->width = readFloat(input);
|
skeletonData->width = readFloat(input);
|
||||||
skeletonData->height = readFloat(input);
|
skeletonData->height = readFloat(input);
|
||||||
skeletonData->referenceScale = readFloat(input);
|
skeletonData->referenceScale = readFloat(input);
|
||||||
|
|
||||||
nonessential = readBoolean(input);
|
nonessential = readBoolean(input);
|
||||||
|
|
||||||
@ -1424,8 +1424,8 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
|
|||||||
data->skinRequired = readBoolean(input);
|
data->skinRequired = readBoolean(input);
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
readColor(input, &data->color.r, &data->color.g, &data->color.b, &data->color.a);
|
readColor(input, &data->color.r, &data->color.g, &data->color.b, &data->color.a);
|
||||||
data->icon = readString(input);
|
data->icon = readString(input);
|
||||||
data->visible = readBoolean(input);
|
data->visible = readBoolean(input);
|
||||||
}
|
}
|
||||||
skeletonData->bones[i] = data;
|
skeletonData->bones[i] = data;
|
||||||
}
|
}
|
||||||
@ -1435,14 +1435,14 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
|
|||||||
skeletonData->slots = MALLOC(spSlotData *, skeletonData->slotsCount);
|
skeletonData->slots = MALLOC(spSlotData *, skeletonData->slotsCount);
|
||||||
for (i = 0; i < skeletonData->slotsCount; ++i) {
|
for (i = 0; i < skeletonData->slotsCount; ++i) {
|
||||||
char *slotName = readString(input);
|
char *slotName = readString(input);
|
||||||
char *pathName = NULL;
|
char *pathName = NULL;
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
int slash = string_lastIndexOf(slotName, '/');
|
int slash = string_lastIndexOf(slotName, '/');
|
||||||
if (slash != -1) {
|
if (slash != -1) {
|
||||||
pathName = string_substring(slotName, 0, slash);
|
pathName = string_substring(slotName, 0, slash);
|
||||||
slotName = string_substring(slotName, slash + 1, strlen(slotName));
|
slotName = string_substring(slotName, slash + 1, strlen(slotName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spBoneData *boneData = skeletonData->bones[readVarint(input, 1)];
|
spBoneData *boneData = skeletonData->bones[readVarint(input, 1)];
|
||||||
spSlotData *slotData = spSlotData_create(i, slotName, boneData);
|
spSlotData *slotData = spSlotData_create(i, slotName, boneData);
|
||||||
FREE(slotName);
|
FREE(slotName);
|
||||||
@ -1460,10 +1460,10 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
|
|||||||
else
|
else
|
||||||
slotData->attachmentName = 0;
|
slotData->attachmentName = 0;
|
||||||
slotData->blendMode = (spBlendMode) readVarint(input, 1);
|
slotData->blendMode = (spBlendMode) readVarint(input, 1);
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
slotData->visible = readBoolean(input);
|
slotData->visible = readBoolean(input);
|
||||||
slotData->path = pathName;
|
slotData->path = pathName;
|
||||||
}
|
}
|
||||||
skeletonData->slots[i] = slotData;
|
skeletonData->slots[i] = slotData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1473,23 +1473,23 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
|
|||||||
for (i = 0; i < skeletonData->ikConstraintsCount; ++i) {
|
for (i = 0; i < skeletonData->ikConstraintsCount; ++i) {
|
||||||
const char *name = readString(input);
|
const char *name = readString(input);
|
||||||
spIkConstraintData *data = spIkConstraintData_create(name);
|
spIkConstraintData *data = spIkConstraintData_create(name);
|
||||||
FREE(name);
|
FREE(name);
|
||||||
data->order = readVarint(input, 1);
|
data->order = readVarint(input, 1);
|
||||||
data->bonesCount = readVarint(input, 1);
|
data->bonesCount = readVarint(input, 1);
|
||||||
data->bones = MALLOC(spBoneData *, data->bonesCount);
|
data->bones = MALLOC(spBoneData *, data->bonesCount);
|
||||||
for (ii = 0; ii < data->bonesCount; ++ii)
|
for (ii = 0; ii < data->bonesCount; ++ii)
|
||||||
data->bones[ii] = skeletonData->bones[readVarint(input, 1)];
|
data->bones[ii] = skeletonData->bones[readVarint(input, 1)];
|
||||||
data->target = skeletonData->bones[readVarint(input, 1)];
|
data->target = skeletonData->bones[readVarint(input, 1)];
|
||||||
int flags = readByte(input);
|
int flags = readByte(input);
|
||||||
data->skinRequired = (flags & 1) != 0;
|
data->skinRequired = (flags & 1) != 0;
|
||||||
data->bendDirection = (flags & 2) != 0 ? 1 : -1;
|
data->bendDirection = (flags & 2) != 0 ? 1 : -1;
|
||||||
data->compress = (flags & 4) != 0;
|
data->compress = (flags & 4) != 0;
|
||||||
data->stretch = (flags & 8) != 0;
|
data->stretch = (flags & 8) != 0;
|
||||||
data->uniform = (flags & 16) != 0;
|
data->uniform = (flags & 16) != 0;
|
||||||
if ((flags & 32) != 0) data->mix = (flags & 64) != 0 ? readFloat(input) : 1;
|
if ((flags & 32) != 0) data->mix = (flags & 64) != 0 ? readFloat(input) : 1;
|
||||||
if ((flags & 128) != 0) data->softness = readFloat(input) * self->scale;
|
if ((flags & 128) != 0) data->softness = readFloat(input) * self->scale;
|
||||||
|
|
||||||
skeletonData->ikConstraints[i] = data;
|
skeletonData->ikConstraints[i] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Transform constraints. */
|
/* Transform constraints. */
|
||||||
@ -1499,32 +1499,32 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
|
|||||||
for (i = 0; i < skeletonData->transformConstraintsCount; ++i) {
|
for (i = 0; i < skeletonData->transformConstraintsCount; ++i) {
|
||||||
const char *name = readString(input);
|
const char *name = readString(input);
|
||||||
spTransformConstraintData *data = spTransformConstraintData_create(name);
|
spTransformConstraintData *data = spTransformConstraintData_create(name);
|
||||||
FREE(name);
|
FREE(name);
|
||||||
data->order = readVarint(input, 1);
|
data->order = readVarint(input, 1);
|
||||||
data->bonesCount = readVarint(input, 1);
|
data->bonesCount = readVarint(input, 1);
|
||||||
data->bones = MALLOC(spBoneData *, data->bonesCount);
|
data->bones = MALLOC(spBoneData *, data->bonesCount);
|
||||||
for (ii = 0; ii < data->bonesCount; ++ii)
|
for (ii = 0; ii < data->bonesCount; ++ii)
|
||||||
data->bones[ii] = skeletonData->bones[readVarint(input, 1)];
|
data->bones[ii] = skeletonData->bones[readVarint(input, 1)];
|
||||||
data->target = skeletonData->bones[readVarint(input, 1)];
|
data->target = skeletonData->bones[readVarint(input, 1)];
|
||||||
int flags = readByte(input);
|
int flags = readByte(input);
|
||||||
data->skinRequired = (flags & 1) != 0;
|
data->skinRequired = (flags & 1) != 0;
|
||||||
data->local = (flags & 2) != 0;
|
data->local = (flags & 2) != 0;
|
||||||
data->relative = (flags & 4) != 0;
|
data->relative = (flags & 4) != 0;
|
||||||
if ((flags & 8) != 0) data->offsetRotation = readFloat(input);
|
if ((flags & 8) != 0) data->offsetRotation = readFloat(input);
|
||||||
if ((flags & 16) != 0) data->offsetX = readFloat(input) * self->scale;
|
if ((flags & 16) != 0) data->offsetX = readFloat(input) * self->scale;
|
||||||
if ((flags & 32) != 0) data->offsetY = readFloat(input) * self->scale;
|
if ((flags & 32) != 0) data->offsetY = readFloat(input) * self->scale;
|
||||||
if ((flags & 64) != 0) data->offsetScaleX = readFloat(input);
|
if ((flags & 64) != 0) data->offsetScaleX = readFloat(input);
|
||||||
if ((flags & 128) != 0) data->offsetScaleY = readFloat(input);
|
if ((flags & 128) != 0) data->offsetScaleY = readFloat(input);
|
||||||
flags = readByte(input);
|
flags = readByte(input);
|
||||||
if ((flags & 1) != 0) data->offsetShearY = readFloat(input);
|
if ((flags & 1) != 0) data->offsetShearY = readFloat(input);
|
||||||
if ((flags & 2) != 0) data->mixRotate = readFloat(input);
|
if ((flags & 2) != 0) data->mixRotate = readFloat(input);
|
||||||
if ((flags & 4) != 0) data->mixX = readFloat(input);
|
if ((flags & 4) != 0) data->mixX = readFloat(input);
|
||||||
if ((flags & 8) != 0) data->mixY = readFloat(input);
|
if ((flags & 8) != 0) data->mixY = readFloat(input);
|
||||||
if ((flags & 16) != 0) data->mixScaleX = readFloat(input);
|
if ((flags & 16) != 0) data->mixScaleX = readFloat(input);
|
||||||
if ((flags & 32) != 0) data->mixScaleY = readFloat(input);
|
if ((flags & 32) != 0) data->mixScaleY = readFloat(input);
|
||||||
if ((flags & 64) != 0) data->mixShearY = readFloat(input);
|
if ((flags & 64) != 0) data->mixShearY = readFloat(input);
|
||||||
|
|
||||||
skeletonData->transformConstraints[i] = data;
|
skeletonData->transformConstraints[i] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Path constraints */
|
/* Path constraints */
|
||||||
@ -1533,7 +1533,7 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
|
|||||||
for (i = 0; i < skeletonData->pathConstraintsCount; ++i) {
|
for (i = 0; i < skeletonData->pathConstraintsCount; ++i) {
|
||||||
const char *name = readString(input);
|
const char *name = readString(input);
|
||||||
spPathConstraintData *data = spPathConstraintData_create(name);
|
spPathConstraintData *data = spPathConstraintData_create(name);
|
||||||
FREE(name);
|
FREE(name);
|
||||||
data->order = readVarint(input, 1);
|
data->order = readVarint(input, 1);
|
||||||
data->skinRequired = readBoolean(input);
|
data->skinRequired = readBoolean(input);
|
||||||
data->bonesCount = readVarint(input, 1);
|
data->bonesCount = readVarint(input, 1);
|
||||||
@ -1541,12 +1541,12 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
|
|||||||
for (ii = 0; ii < data->bonesCount; ++ii)
|
for (ii = 0; ii < data->bonesCount; ++ii)
|
||||||
data->bones[ii] = skeletonData->bones[readVarint(input, 1)];
|
data->bones[ii] = skeletonData->bones[readVarint(input, 1)];
|
||||||
data->target = skeletonData->slots[readVarint(input, 1)];
|
data->target = skeletonData->slots[readVarint(input, 1)];
|
||||||
int flags = readByte(input);
|
int flags = readByte(input);
|
||||||
data->positionMode = (flags & 1);
|
data->positionMode = (flags & 1);
|
||||||
data->spacingMode = ((flags >> 1) & 3);
|
data->spacingMode = ((flags >> 1) & 3);
|
||||||
data->rotateMode = ((flags >> 3) & 3);
|
data->rotateMode = ((flags >> 3) & 3);
|
||||||
if ((flags & 128) != 0) data->offsetRotation = readFloat(input);
|
if ((flags & 128) != 0) data->offsetRotation = readFloat(input);
|
||||||
data->position = readFloat(input);
|
data->position = readFloat(input);
|
||||||
if (data->positionMode == SP_POSITION_MODE_FIXED) data->position *= self->scale;
|
if (data->positionMode == SP_POSITION_MODE_FIXED) data->position *= self->scale;
|
||||||
data->spacing = readFloat(input);
|
data->spacing = readFloat(input);
|
||||||
if (data->spacingMode == SP_SPACING_MODE_LENGTH || data->spacingMode == SP_SPACING_MODE_FIXED)
|
if (data->spacingMode == SP_SPACING_MODE_LENGTH || data->spacingMode == SP_SPACING_MODE_FIXED)
|
||||||
@ -1557,41 +1557,41 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
|
|||||||
skeletonData->pathConstraints[i] = data;
|
skeletonData->pathConstraints[i] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Physics constraints.
|
// Physics constraints.
|
||||||
skeletonData->physicsConstraintsCount = readVarint(input, 1);
|
skeletonData->physicsConstraintsCount = readVarint(input, 1);
|
||||||
skeletonData->physicsConstraints = MALLOC(spPhysicsConstraintData *, skeletonData->physicsConstraintsCount);
|
skeletonData->physicsConstraints = MALLOC(spPhysicsConstraintData *, skeletonData->physicsConstraintsCount);
|
||||||
for (i = 0; i < skeletonData->physicsConstraintsCount; i++) {
|
for (i = 0; i < skeletonData->physicsConstraintsCount; i++) {
|
||||||
const char *name = readString(input);
|
const char *name = readString(input);
|
||||||
spPhysicsConstraintData *data = spPhysicsConstraintData_create(name);
|
spPhysicsConstraintData *data = spPhysicsConstraintData_create(name);
|
||||||
FREE(name);
|
FREE(name);
|
||||||
data->order = readVarint(input, 1);
|
data->order = readVarint(input, 1);
|
||||||
data->bone = skeletonData->bones[readVarint(input, 1)];
|
data->bone = skeletonData->bones[readVarint(input, 1)];
|
||||||
int flags = readByte(input);
|
int flags = readByte(input);
|
||||||
data->skinRequired = (flags & 1) != 0;
|
data->skinRequired = (flags & 1) != 0;
|
||||||
if ((flags & 2) != 0) data->x = readFloat(input);
|
if ((flags & 2) != 0) data->x = readFloat(input);
|
||||||
if ((flags & 4) != 0) data->y = readFloat(input);
|
if ((flags & 4) != 0) data->y = readFloat(input);
|
||||||
if ((flags & 8) != 0) data->rotate = readFloat(input);
|
if ((flags & 8) != 0) data->rotate = readFloat(input);
|
||||||
if ((flags & 16) != 0) data->scaleX = readFloat(input);
|
if ((flags & 16) != 0) data->scaleX = readFloat(input);
|
||||||
if ((flags & 32) != 0) data->shearX = readFloat(input);
|
if ((flags & 32) != 0) data->shearX = readFloat(input);
|
||||||
data->limit = ((flags & 64) != 0 ? readFloat(input) : 5000) * self->scale;
|
data->limit = ((flags & 64) != 0 ? readFloat(input) : 5000) * self->scale;
|
||||||
data->step = 1.f / readByte(input);
|
data->step = 1.f / readByte(input);
|
||||||
data->inertia = readFloat(input);
|
data->inertia = readFloat(input);
|
||||||
data->strength = readFloat(input);
|
data->strength = readFloat(input);
|
||||||
data->damping = readFloat(input);
|
data->damping = readFloat(input);
|
||||||
data->massInverse = (flags & 128) != 0 ? readFloat(input) : 1;
|
data->massInverse = (flags & 128) != 0 ? readFloat(input) : 1;
|
||||||
data->wind = readFloat(input);
|
data->wind = readFloat(input);
|
||||||
data->gravity = readFloat(input);
|
data->gravity = readFloat(input);
|
||||||
flags = readByte(input);
|
flags = readByte(input);
|
||||||
if ((flags & 1) != 0) data->inertiaGlobal = -1;
|
if ((flags & 1) != 0) data->inertiaGlobal = -1;
|
||||||
if ((flags & 2) != 0) data->strengthGlobal = -1;
|
if ((flags & 2) != 0) data->strengthGlobal = -1;
|
||||||
if ((flags & 4) != 0) data->dampingGlobal = -1;
|
if ((flags & 4) != 0) data->dampingGlobal = -1;
|
||||||
if ((flags & 8) != 0) data->massGlobal = -1;
|
if ((flags & 8) != 0) data->massGlobal = -1;
|
||||||
if ((flags & 16) != 0) data->windGlobal = -1;
|
if ((flags & 16) != 0) data->windGlobal = -1;
|
||||||
if ((flags & 32) != 0) data->gravityGlobal = -1;
|
if ((flags & 32) != 0) data->gravityGlobal = -1;
|
||||||
if ((flags & 64) != 0) data->mixGlobal = -1;
|
if ((flags & 64) != 0) data->mixGlobal = -1;
|
||||||
data->mix = (flags & 128) != 0 ? readFloat(input) : 1;
|
data->mix = (flags & 128) != 0 ? readFloat(input) : 1;
|
||||||
skeletonData->physicsConstraints[i] = data;
|
skeletonData->physicsConstraints[i] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Default skin. */
|
/* Default skin. */
|
||||||
skeletonData->defaultSkin = spSkeletonBinary_readSkin(self, input, -1, skeletonData, nonessential);
|
skeletonData->defaultSkin = spSkeletonBinary_readSkin(self, input, -1, skeletonData, nonessential);
|
||||||
@ -1624,14 +1624,14 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
|
|||||||
/* Linked meshes. */
|
/* Linked meshes. */
|
||||||
for (i = 0; i < internal->linkedMeshCount; ++i) {
|
for (i = 0; i < internal->linkedMeshCount; ++i) {
|
||||||
_spLinkedMesh *linkedMesh = internal->linkedMeshes + i;
|
_spLinkedMesh *linkedMesh = internal->linkedMeshes + i;
|
||||||
spSkin *skin = skeletonData->skins[linkedMesh->skinIndex];
|
spSkin *skin = skeletonData->skins[linkedMesh->skinIndex];
|
||||||
if (!skin) {
|
if (!skin) {
|
||||||
FREE(input);
|
FREE(input);
|
||||||
spSkeletonData_dispose(skeletonData);
|
spSkeletonData_dispose(skeletonData);
|
||||||
_spSkeletonBinary_setError(self, "Skin not found", "");
|
_spSkeletonBinary_setError(self, "Skin not found", "");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
spAttachment *parent = spSkin_getAttachment(skin, linkedMesh->slotIndex, linkedMesh->parent);
|
spAttachment *parent = spSkin_getAttachment(skin, linkedMesh->slotIndex, linkedMesh->parent);
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
FREE(input);
|
FREE(input);
|
||||||
spSkeletonData_dispose(skeletonData);
|
spSkeletonData_dispose(skeletonData);
|
||||||
@ -1651,7 +1651,7 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
|
|||||||
for (i = 0; i < skeletonData->eventsCount; ++i) {
|
for (i = 0; i < skeletonData->eventsCount; ++i) {
|
||||||
const char *name = readString(input);
|
const char *name = readString(input);
|
||||||
spEventData *eventData = spEventData_create(name);
|
spEventData *eventData = spEventData_create(name);
|
||||||
FREE(name);
|
FREE(name);
|
||||||
eventData->intValue = readVarint(input, 0);
|
eventData->intValue = readVarint(input, 0);
|
||||||
eventData->floatValue = readFloat(input);
|
eventData->floatValue = readFloat(input);
|
||||||
eventData->stringValue = readString(input);
|
eventData->stringValue = readString(input);
|
||||||
|
|||||||
@ -74,9 +74,9 @@ void spSkeletonData_dispose(spSkeletonData *self) {
|
|||||||
spPathConstraintData_dispose(self->pathConstraints[i]);
|
spPathConstraintData_dispose(self->pathConstraints[i]);
|
||||||
FREE(self->pathConstraints);
|
FREE(self->pathConstraints);
|
||||||
|
|
||||||
for (i = 0; i < self->physicsConstraintsCount; i++)
|
for (i = 0; i < self->physicsConstraintsCount; i++)
|
||||||
spPhysicsConstraintData_dispose(self->physicsConstraints[i]);
|
spPhysicsConstraintData_dispose(self->physicsConstraints[i]);
|
||||||
FREE(self->physicsConstraints);
|
FREE(self->physicsConstraints);
|
||||||
|
|
||||||
FREE(self->hash);
|
FREE(self->hash);
|
||||||
FREE(self->version);
|
FREE(self->version);
|
||||||
@ -144,8 +144,8 @@ spPathConstraintData *spSkeletonData_findPathConstraint(const spSkeletonData *se
|
|||||||
}
|
}
|
||||||
|
|
||||||
spPhysicsConstraintData *spSkeletonData_findPhysicsConstraint(const spSkeletonData *self, const char *constraintName) {
|
spPhysicsConstraintData *spSkeletonData_findPhysicsConstraint(const spSkeletonData *self, const char *constraintName) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < self->physicsConstraintsCount; ++i)
|
for (i = 0; i < self->physicsConstraintsCount; ++i)
|
||||||
if (strcmp(self->physicsConstraints[i]->name, constraintName) == 0) return self->physicsConstraints[i];
|
if (strcmp(self->physicsConstraints[i]->name, constraintName) == 0) return self->physicsConstraints[i];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -269,14 +269,14 @@ int findPathConstraintIndex(spSkeletonJson *json, const spSkeletonData *skeleton
|
|||||||
}
|
}
|
||||||
|
|
||||||
int findPhysicsConstraintIndex(spSkeletonJson *json, const spSkeletonData *skeletonData, const spPhysicsConstraintData *constraint, spTimelineArray *timelines) {
|
int findPhysicsConstraintIndex(spSkeletonJson *json, const spSkeletonData *skeletonData, const spPhysicsConstraintData *constraint, spTimelineArray *timelines) {
|
||||||
if (constraint) {
|
if (constraint) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < skeletonData->physicsConstraintsCount; ++i)
|
for (i = 0; i < skeletonData->physicsConstraintsCount; ++i)
|
||||||
if (skeletonData->physicsConstraints[i] == constraint) return i;
|
if (skeletonData->physicsConstraints[i] == constraint) return i;
|
||||||
}
|
}
|
||||||
cleanUpTimelines(timelines);
|
cleanUpTimelines(timelines);
|
||||||
_spSkeletonJson_setError(json, NULL, "Physics constraint not found: ", constraint->name);
|
_spSkeletonJson_setError(json, NULL, "Physics constraint not found: ", constraint->name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static spAnimation *_spSkeletonJson_readAnimation(spSkeletonJson *self, Json *root, spSkeletonData *skeletonData) {
|
static spAnimation *_spSkeletonJson_readAnimation(spSkeletonJson *self, Json *root, spSkeletonData *skeletonData) {
|
||||||
@ -288,7 +288,7 @@ static spAnimation *_spSkeletonJson_readAnimation(spSkeletonJson *self, Json *ro
|
|||||||
Json *ik = Json_getItem(root, "ik");
|
Json *ik = Json_getItem(root, "ik");
|
||||||
Json *transform = Json_getItem(root, "transform");
|
Json *transform = Json_getItem(root, "transform");
|
||||||
Json *paths = Json_getItem(root, "path");
|
Json *paths = Json_getItem(root, "path");
|
||||||
Json *physics = Json_getItem(root, "physics");
|
Json *physics = Json_getItem(root, "physics");
|
||||||
Json *attachmentsJson = Json_getItem(root, "attachments");
|
Json *attachmentsJson = Json_getItem(root, "attachments");
|
||||||
Json *drawOrderJson = Json_getItem(root, "drawOrder");
|
Json *drawOrderJson = Json_getItem(root, "drawOrder");
|
||||||
Json *events = Json_getItem(root, "events");
|
Json *events = Json_getItem(root, "events");
|
||||||
@ -528,29 +528,29 @@ static spAnimation *_spSkeletonJson_readAnimation(spSkeletonJson *self, Json *ro
|
|||||||
spShearXTimeline *timeline = spShearXTimeline_create(frames, frames, boneIndex);
|
spShearXTimeline *timeline = spShearXTimeline_create(frames, frames, boneIndex);
|
||||||
spTimelineArray_add(timelines, readTimeline(timelineMap->child, SUPER(timeline), 0, 1));
|
spTimelineArray_add(timelines, readTimeline(timelineMap->child, SUPER(timeline), 0, 1));
|
||||||
} else if (strcmp(timelineMap->name, "sheary") == 0) {
|
} else if (strcmp(timelineMap->name, "sheary") == 0) {
|
||||||
spShearYTimeline *timeline = spShearYTimeline_create(frames, frames, boneIndex);
|
spShearYTimeline *timeline = spShearYTimeline_create(frames, frames, boneIndex);
|
||||||
spTimelineArray_add(timelines, readTimeline(timelineMap->child, SUPER(timeline), 0, 1));
|
spTimelineArray_add(timelines, readTimeline(timelineMap->child, SUPER(timeline), 0, 1));
|
||||||
} else if (strcmp(timelineMap->name, "inherit") == 0) {
|
} else if (strcmp(timelineMap->name, "inherit") == 0) {
|
||||||
spInheritTimeline *timeline = spInheritTimeline_create(frames, boneIndex);
|
spInheritTimeline *timeline = spInheritTimeline_create(frames, boneIndex);
|
||||||
keyMap = timelineMap->child;
|
keyMap = timelineMap->child;
|
||||||
for (frame = 0;; frame++) {
|
for (frame = 0;; frame++) {
|
||||||
float time = Json_getFloat(keyMap, "time", 0);
|
float time = Json_getFloat(keyMap, "time", 0);
|
||||||
const char *value = Json_getString(keyMap, "value", "normal");
|
const char *value = Json_getString(keyMap, "value", "normal");
|
||||||
spInherit inherit = SP_INHERIT_NORMAL;
|
spInherit inherit = SP_INHERIT_NORMAL;
|
||||||
if (strcmp(value, "normal") == 0) inherit = SP_INHERIT_NORMAL;
|
if (strcmp(value, "normal") == 0) inherit = SP_INHERIT_NORMAL;
|
||||||
else if (strcmp(value, "onlyTranslation") == 0)
|
else if (strcmp(value, "onlyTranslation") == 0)
|
||||||
inherit = SP_INHERIT_ONLYTRANSLATION;
|
inherit = SP_INHERIT_ONLYTRANSLATION;
|
||||||
else if (strcmp(value, "noRotationOrReflection") == 0)
|
else if (strcmp(value, "noRotationOrReflection") == 0)
|
||||||
inherit = SP_INHERIT_NOROTATIONORREFLECTION;
|
inherit = SP_INHERIT_NOROTATIONORREFLECTION;
|
||||||
else if (strcmp(value, "noScale") == 0)
|
else if (strcmp(value, "noScale") == 0)
|
||||||
inherit = SP_INHERIT_NOSCALE;
|
inherit = SP_INHERIT_NOSCALE;
|
||||||
else if (strcmp(value, "noScaleOrReflection") == 0)
|
else if (strcmp(value, "noScaleOrReflection") == 0)
|
||||||
inherit = SP_INHERIT_NOSCALEORREFLECTION;
|
inherit = SP_INHERIT_NOSCALEORREFLECTION;
|
||||||
spInheritTimeline_setFrame(timeline, frame, time, inherit);
|
spInheritTimeline_setFrame(timeline, frame, time, inherit);
|
||||||
nextMap = keyMap->next;
|
nextMap = keyMap->next;
|
||||||
if (!nextMap) break;
|
if (!nextMap) break;
|
||||||
}
|
}
|
||||||
spTimelineArray_add(timelines, SUPER(timeline));
|
spTimelineArray_add(timelines, SUPER(timeline));
|
||||||
} else {
|
} else {
|
||||||
cleanUpTimelines(timelines);
|
cleanUpTimelines(timelines);
|
||||||
_spSkeletonJson_setError(self, NULL, "Invalid timeline type for a bone: ", timelineMap->name);
|
_spSkeletonJson_setError(self, NULL, "Invalid timeline type for a bone: ", timelineMap->name);
|
||||||
@ -734,49 +734,49 @@ static spAnimation *_spSkeletonJson_readAnimation(spSkeletonJson *self, Json *ro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Physics constraint timelines. */
|
/** Physics constraint timelines. */
|
||||||
for (constraintMap = physics ? physics->child : 0; constraintMap; constraintMap = constraintMap->next) {
|
for (constraintMap = physics ? physics->child : 0; constraintMap; constraintMap = constraintMap->next) {
|
||||||
int index = -1;
|
int index = -1;
|
||||||
if (constraintMap->name && strlen(constraintMap->name) > 0) {
|
if (constraintMap->name && strlen(constraintMap->name) > 0) {
|
||||||
spPhysicsConstraintData *constraint = spSkeletonData_findPhysicsConstraint(skeletonData, constraintMap->name);
|
spPhysicsConstraintData *constraint = spSkeletonData_findPhysicsConstraint(skeletonData, constraintMap->name);
|
||||||
index = findPhysicsConstraintIndex(self, skeletonData, constraint, timelines);
|
index = findPhysicsConstraintIndex(self, skeletonData, constraint, timelines);
|
||||||
if (index == -1) return NULL;
|
if (index == -1) return NULL;
|
||||||
}
|
}
|
||||||
for (timelineMap = constraintMap->child; timelineMap; timelineMap = timelineMap->next) {
|
for (timelineMap = constraintMap->child; timelineMap; timelineMap = timelineMap->next) {
|
||||||
keyMap = timelineMap->child;
|
keyMap = timelineMap->child;
|
||||||
if (keyMap == NULL) continue;
|
if (keyMap == NULL) continue;
|
||||||
const char *timelineName = timelineMap->name;
|
const char *timelineName = timelineMap->name;
|
||||||
int frames = timelineMap->size;
|
int frames = timelineMap->size;
|
||||||
if (strcmp(timelineName, "reset") == 0) {
|
if (strcmp(timelineName, "reset") == 0) {
|
||||||
spPhysicsConstraintResetTimeline *timeline = spPhysicsConstraintResetTimeline_create(frames, index);
|
spPhysicsConstraintResetTimeline *timeline = spPhysicsConstraintResetTimeline_create(frames, index);
|
||||||
for (frame = 0; keyMap != NULL; keyMap = keyMap->next, frame++) {
|
for (frame = 0; keyMap != NULL; keyMap = keyMap->next, frame++) {
|
||||||
spPhysicsConstraintResetTimeline_setFrame(timeline, frame, Json_getFloat(keyMap, "time", 0));
|
spPhysicsConstraintResetTimeline_setFrame(timeline, frame, Json_getFloat(keyMap, "time", 0));
|
||||||
}
|
}
|
||||||
spTimelineArray_add(timelines, SUPER(timeline));
|
spTimelineArray_add(timelines, SUPER(timeline));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
spPhysicsConstraintTimeline *timeline = NULL;
|
spPhysicsConstraintTimeline *timeline = NULL;
|
||||||
if (strcmp(timelineName, "inertia") == 0) {
|
if (strcmp(timelineName, "inertia") == 0) {
|
||||||
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA);
|
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA);
|
||||||
} else if (strcmp(timelineName, "strength") == 0) {
|
} else if (strcmp(timelineName, "strength") == 0) {
|
||||||
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH);
|
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH);
|
||||||
} else if (strcmp(timelineName, "damping") == 0) {
|
} else if (strcmp(timelineName, "damping") == 0) {
|
||||||
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING);
|
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING);
|
||||||
} else if (strcmp(timelineName, "mass") == 0) {
|
} else if (strcmp(timelineName, "mass") == 0) {
|
||||||
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_MASS);
|
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_MASS);
|
||||||
} else if (strcmp(timelineName, "wind") == 0) {
|
} else if (strcmp(timelineName, "wind") == 0) {
|
||||||
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_WIND);
|
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_WIND);
|
||||||
} else if (strcmp(timelineName, "gravity") == 0) {
|
} else if (strcmp(timelineName, "gravity") == 0) {
|
||||||
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY);
|
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY);
|
||||||
} else if (strcmp(timelineName, "mix") == 0) {
|
} else if (strcmp(timelineName, "mix") == 0) {
|
||||||
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_MIX);
|
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_MIX);
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
spTimelineArray_add(timelines, readTimeline(keyMap, SUPER(timeline), 0, 1));
|
spTimelineArray_add(timelines, readTimeline(keyMap, SUPER(timeline), 0, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Attachment timelines. */
|
/* Attachment timelines. */
|
||||||
for (attachmentsMap = attachmentsJson ? attachmentsJson->child : 0; attachmentsMap; attachmentsMap = attachmentsMap->next) {
|
for (attachmentsMap = attachmentsJson ? attachmentsJson->child : 0; attachmentsMap; attachmentsMap = attachmentsMap->next) {
|
||||||
@ -1042,31 +1042,31 @@ static int string_starts_with(const char *str, const char *needle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int string_lastIndexOf(const char *str, char needle) {
|
static int string_lastIndexOf(const char *str, char needle) {
|
||||||
if (!str) return -1;
|
if (!str) return -1;
|
||||||
int lastIndex = -1;
|
int lastIndex = -1;
|
||||||
for (int i = 0; str[i] != '\0'; i++) {
|
for (int i = 0; str[i] != '\0'; i++) {
|
||||||
if (str[i] == needle) {
|
if (str[i] == needle) {
|
||||||
lastIndex = i;
|
lastIndex = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lastIndex;
|
return lastIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *string_substring(const char *str, int start, int end) {
|
static char *string_substring(const char *str, int start, int end) {
|
||||||
if (str == NULL || start > end || start < 0) {
|
if (str == NULL || start > end || start < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = end - start;
|
int len = end - start;
|
||||||
char *substr = MALLOC(char, len + 1);
|
char *substr = MALLOC(char, len + 1);
|
||||||
if (substr == NULL) {
|
if (substr == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(substr, str + start, len);
|
strncpy(substr, str + start, len);
|
||||||
substr[len] = '\0';
|
substr[len] = '\0';
|
||||||
|
|
||||||
return substr;
|
return substr;
|
||||||
}
|
}
|
||||||
|
|
||||||
spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char *json) {
|
spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char *json) {
|
||||||
@ -1101,7 +1101,7 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
|
|||||||
skeletonData->y = Json_getFloat(skeleton, "y", 0);
|
skeletonData->y = Json_getFloat(skeleton, "y", 0);
|
||||||
skeletonData->width = Json_getFloat(skeleton, "width", 0);
|
skeletonData->width = Json_getFloat(skeleton, "width", 0);
|
||||||
skeletonData->height = Json_getFloat(skeleton, "height", 0);
|
skeletonData->height = Json_getFloat(skeleton, "height", 0);
|
||||||
skeletonData->referenceScale = Json_getFloat(skeleton, "referenceScale", 100) * self->scale;
|
skeletonData->referenceScale = Json_getFloat(skeleton, "referenceScale", 100) * self->scale;
|
||||||
skeletonData->fps = Json_getFloat(skeleton, "fps", 30);
|
skeletonData->fps = Json_getFloat(skeleton, "fps", 30);
|
||||||
skeletonData->imagesPath = Json_getString(skeleton, "images", 0);
|
skeletonData->imagesPath = Json_getString(skeleton, "images", 0);
|
||||||
if (skeletonData->imagesPath) {
|
if (skeletonData->imagesPath) {
|
||||||
@ -1161,13 +1161,13 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
|
|||||||
color = Json_getString(boneMap, "color", 0);
|
color = Json_getString(boneMap, "color", 0);
|
||||||
if (color) toColor2(&data->color, color, -1);
|
if (color) toColor2(&data->color, color, -1);
|
||||||
|
|
||||||
data->icon = Json_getString(boneMap, "icon", "");
|
data->icon = Json_getString(boneMap, "icon", "");
|
||||||
if (data->icon) {
|
if (data->icon) {
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
MALLOC_STR(tmp, data->icon);
|
MALLOC_STR(tmp, data->icon);
|
||||||
data->icon = tmp;
|
data->icon = tmp;
|
||||||
}
|
}
|
||||||
data->visible = Json_getInt(boneMap, "visible", -1) ? -1 : 0;
|
data->visible = Json_getInt(boneMap, "visible", -1) ? -1 : 0;
|
||||||
|
|
||||||
skeletonData->bones[i] = data;
|
skeletonData->bones[i] = data;
|
||||||
skeletonData->bonesCount++;
|
skeletonData->bonesCount++;
|
||||||
@ -1193,13 +1193,13 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pathName = NULL;
|
char *pathName = NULL;
|
||||||
char *slotName = (char*)Json_getString(slotMap, "name", NULL);
|
char *slotName = (char *) Json_getString(slotMap, "name", NULL);
|
||||||
int slash = string_lastIndexOf(slotName, '/');
|
int slash = string_lastIndexOf(slotName, '/');
|
||||||
if (slash != -1) {
|
if (slash != -1) {
|
||||||
pathName = string_substring(slotName, 0, slash);
|
pathName = string_substring(slotName, 0, slash);
|
||||||
slotName = string_substring(slotName, slash + 1, strlen(slotName));
|
slotName = string_substring(slotName, slash + 1, strlen(slotName));
|
||||||
}
|
}
|
||||||
data = spSlotData_create(i, slotName, boneData);
|
data = spSlotData_create(i, slotName, boneData);
|
||||||
|
|
||||||
color = Json_getString(slotMap, "color", 0);
|
color = Json_getString(slotMap, "color", 0);
|
||||||
@ -1234,8 +1234,8 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
|
|||||||
data->blendMode = SP_BLEND_MODE_SCREEN;
|
data->blendMode = SP_BLEND_MODE_SCREEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->visible = Json_getInt(slotMap, "visible", -1);
|
data->visible = Json_getInt(slotMap, "visible", -1);
|
||||||
data->path = pathName;
|
data->path = pathName;
|
||||||
skeletonData->slots[i] = data;
|
skeletonData->slots[i] = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1407,53 +1407,53 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Physics constraints */
|
/* Physics constraints */
|
||||||
physics = Json_getItem(root, "physics");
|
physics = Json_getItem(root, "physics");
|
||||||
if (physics) {
|
if (physics) {
|
||||||
Json *constraintMap;
|
Json *constraintMap;
|
||||||
skeletonData->physicsConstraintsCount = physics->size;
|
skeletonData->physicsConstraintsCount = physics->size;
|
||||||
skeletonData->physicsConstraints = MALLOC(spPhysicsConstraintData *, physics->size);
|
skeletonData->physicsConstraints = MALLOC(spPhysicsConstraintData *, physics->size);
|
||||||
for (constraintMap = physics->child, i = 0; constraintMap; constraintMap = constraintMap->next, ++i) {
|
for (constraintMap = physics->child, i = 0; constraintMap; constraintMap = constraintMap->next, ++i) {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
spPhysicsConstraintData *data = spPhysicsConstraintData_create(
|
spPhysicsConstraintData *data = spPhysicsConstraintData_create(
|
||||||
Json_getString(constraintMap, "name", 0));
|
Json_getString(constraintMap, "name", 0));
|
||||||
data->order = Json_getInt(constraintMap, "order", 0);
|
data->order = Json_getInt(constraintMap, "order", 0);
|
||||||
data->skinRequired = Json_getInt(constraintMap, "skin", 0);
|
data->skinRequired = Json_getInt(constraintMap, "skin", 0);
|
||||||
|
|
||||||
name = Json_getString(constraintMap, "bone", 0);
|
name = Json_getString(constraintMap, "bone", 0);
|
||||||
data->bone = spSkeletonData_findBone(skeletonData, name);
|
data->bone = spSkeletonData_findBone(skeletonData, name);
|
||||||
if (!data->bone) {
|
if (!data->bone) {
|
||||||
spSkeletonData_dispose(skeletonData);
|
spSkeletonData_dispose(skeletonData);
|
||||||
_spSkeletonJson_setError(self, root, "Physics bone not found: ", name);
|
_spSkeletonJson_setError(self, root, "Physics bone not found: ", name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->x = Json_getFloat(constraintMap, "x", 0);
|
data->x = Json_getFloat(constraintMap, "x", 0);
|
||||||
data->y = Json_getFloat(constraintMap, "y", 0);
|
data->y = Json_getFloat(constraintMap, "y", 0);
|
||||||
data->rotate = Json_getFloat(constraintMap, "rotate", 0);
|
data->rotate = Json_getFloat(constraintMap, "rotate", 0);
|
||||||
data->scaleX = Json_getFloat(constraintMap, "scaleX", 0);
|
data->scaleX = Json_getFloat(constraintMap, "scaleX", 0);
|
||||||
data->shearX = Json_getFloat(constraintMap, "shearX", 0);
|
data->shearX = Json_getFloat(constraintMap, "shearX", 0);
|
||||||
data->limit = Json_getFloat(constraintMap, "limit", 5000) * self->scale;
|
data->limit = Json_getFloat(constraintMap, "limit", 5000) * self->scale;
|
||||||
data->step = 1.0f / Json_getInt(constraintMap, "fps", 60);
|
data->step = 1.0f / Json_getInt(constraintMap, "fps", 60);
|
||||||
data->inertia = Json_getFloat(constraintMap, "inertia", 1);
|
data->inertia = Json_getFloat(constraintMap, "inertia", 1);
|
||||||
data->strength = Json_getFloat(constraintMap, "strength", 100);
|
data->strength = Json_getFloat(constraintMap, "strength", 100);
|
||||||
data->damping = Json_getFloat(constraintMap, "damping", 1);
|
data->damping = Json_getFloat(constraintMap, "damping", 1);
|
||||||
data->massInverse = 1.0f / Json_getFloat(constraintMap, "mass", 1);
|
data->massInverse = 1.0f / Json_getFloat(constraintMap, "mass", 1);
|
||||||
data->wind = Json_getFloat(constraintMap, "wind", 0);
|
data->wind = Json_getFloat(constraintMap, "wind", 0);
|
||||||
data->gravity = Json_getFloat(constraintMap, "gravity", 0);
|
data->gravity = Json_getFloat(constraintMap, "gravity", 0);
|
||||||
data->mix = Json_getFloat(constraintMap, "mix", 1);
|
data->mix = Json_getFloat(constraintMap, "mix", 1);
|
||||||
data->inertiaGlobal = Json_getInt(constraintMap, "inertiaGlobal", 0);
|
data->inertiaGlobal = Json_getInt(constraintMap, "inertiaGlobal", 0);
|
||||||
data->strengthGlobal = Json_getInt(constraintMap, "strengthGlobal", 0);
|
data->strengthGlobal = Json_getInt(constraintMap, "strengthGlobal", 0);
|
||||||
data->dampingGlobal = Json_getInt(constraintMap, "dampingGlobal", 0);
|
data->dampingGlobal = Json_getInt(constraintMap, "dampingGlobal", 0);
|
||||||
data->massGlobal = Json_getInt(constraintMap, "massGlobal", 0);
|
data->massGlobal = Json_getInt(constraintMap, "massGlobal", 0);
|
||||||
data->windGlobal = Json_getInt(constraintMap, "windGlobal", 0);
|
data->windGlobal = Json_getInt(constraintMap, "windGlobal", 0);
|
||||||
data->gravityGlobal = Json_getInt(constraintMap, "gravityGlobal", 0);
|
data->gravityGlobal = Json_getInt(constraintMap, "gravityGlobal", 0);
|
||||||
data->mixGlobal = Json_getInt(constraintMap, "mixGlobal", 0);
|
data->mixGlobal = Json_getInt(constraintMap, "mixGlobal", 0);
|
||||||
|
|
||||||
skeletonData->physicsConstraints[i] = data;
|
skeletonData->physicsConstraints[i] = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skins. */
|
/* Skins. */
|
||||||
skins = Json_getItem(root, "skins");
|
skins = Json_getItem(root, "skins");
|
||||||
@ -1522,19 +1522,19 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
skinPart = Json_getItem(skinMap, "physics");
|
skinPart = Json_getItem(skinMap, "physics");
|
||||||
if (skinPart) {
|
if (skinPart) {
|
||||||
for (skinPart = skinPart->child; skinPart; skinPart = skinPart->next) {
|
for (skinPart = skinPart->child; skinPart; skinPart = skinPart->next) {
|
||||||
spPhysicsConstraintData *constraint = spSkeletonData_findPhysicsConstraint(skeletonData,
|
spPhysicsConstraintData *constraint = spSkeletonData_findPhysicsConstraint(skeletonData,
|
||||||
skinPart->valueString);
|
skinPart->valueString);
|
||||||
if (!constraint) {
|
if (!constraint) {
|
||||||
spSkeletonData_dispose(skeletonData);
|
spSkeletonData_dispose(skeletonData);
|
||||||
_spSkeletonJson_setError(self, root, "Skin physics constraint not found: ", skinPart->valueString);
|
_spSkeletonJson_setError(self, root, "Skin physics constraint not found: ", skinPart->valueString);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
spPhysicsConstraintDataArray_add(skin->physicsConstraints, constraint);
|
spPhysicsConstraintDataArray_add(skin->physicsConstraints, constraint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
skeletonData->skins[skeletonData->skinsCount++] = skin;
|
skeletonData->skins[skeletonData->skinsCount++] = skin;
|
||||||
if (strcmp(skin->name, "default") == 0) skeletonData->defaultSkin = skin;
|
if (strcmp(skin->name, "default") == 0) skeletonData->defaultSkin = skin;
|
||||||
@ -1661,7 +1661,7 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
|
|||||||
mesh->edgesCount = entry->size;
|
mesh->edgesCount = entry->size;
|
||||||
mesh->edges = MALLOC(unsigned short, entry->size);
|
mesh->edges = MALLOC(unsigned short, entry->size);
|
||||||
for (entry = entry->child, ii = 0; entry; entry = entry->next, ++ii)
|
for (entry = entry->child, ii = 0; entry; entry = entry->next, ++ii)
|
||||||
mesh->edges[ii] = (unsigned short)entry->valueInt;
|
mesh->edges[ii] = (unsigned short) entry->valueInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
|
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
|
||||||
|
|||||||
@ -44,7 +44,7 @@ _SP_ARRAY_IMPLEMENT_TYPE(spPhysicsConstraintDataArray, spPhysicsConstraintData *
|
|||||||
_Entry *_Entry_create(int slotIndex, const char *name, spAttachment *attachment) {
|
_Entry *_Entry_create(int slotIndex, const char *name, spAttachment *attachment) {
|
||||||
_Entry *self = NEW(_Entry);
|
_Entry *self = NEW(_Entry);
|
||||||
self->slotIndex = slotIndex;
|
self->slotIndex = slotIndex;
|
||||||
MALLOC_STR(self->name, (char *)name);
|
MALLOC_STR(self->name, (char *) name);
|
||||||
self->attachment = attachment;
|
self->attachment = attachment;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -69,13 +69,13 @@ static void _SkinHashTableEntry_dispose(_SkinHashTableEntry *self) {
|
|||||||
|
|
||||||
spSkin *spSkin_create(const char *name) {
|
spSkin *spSkin_create(const char *name) {
|
||||||
spSkin *self = SUPER(NEW(_spSkin));
|
spSkin *self = SUPER(NEW(_spSkin));
|
||||||
MALLOC_STR(self->name, (char*)name);
|
MALLOC_STR(self->name, (char *) name);
|
||||||
self->bones = spBoneDataArray_create(4);
|
self->bones = spBoneDataArray_create(4);
|
||||||
self->ikConstraints = spIkConstraintDataArray_create(4);
|
self->ikConstraints = spIkConstraintDataArray_create(4);
|
||||||
self->transformConstraints = spTransformConstraintDataArray_create(4);
|
self->transformConstraints = spTransformConstraintDataArray_create(4);
|
||||||
self->pathConstraints = spPathConstraintDataArray_create(4);
|
self->pathConstraints = spPathConstraintDataArray_create(4);
|
||||||
self->physicsConstraints = spPhysicsConstraintDataArray_create(4);
|
self->physicsConstraints = spPhysicsConstraintDataArray_create(4);
|
||||||
spColor_setFromFloats(&self->color, 0.99607843f, 0.61960787f, 0.30980393f, 1);
|
spColor_setFromFloats(&self->color, 0.99607843f, 0.61960787f, 0.30980393f, 1);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ void spSkin_dispose(spSkin *self) {
|
|||||||
spIkConstraintDataArray_dispose(self->ikConstraints);
|
spIkConstraintDataArray_dispose(self->ikConstraints);
|
||||||
spTransformConstraintDataArray_dispose(self->transformConstraints);
|
spTransformConstraintDataArray_dispose(self->transformConstraints);
|
||||||
spPathConstraintDataArray_dispose(self->pathConstraints);
|
spPathConstraintDataArray_dispose(self->pathConstraints);
|
||||||
spPhysicsConstraintDataArray_dispose(self->physicsConstraints);
|
spPhysicsConstraintDataArray_dispose(self->physicsConstraints);
|
||||||
FREE(self->name);
|
FREE(self->name);
|
||||||
FREE(self);
|
FREE(self);
|
||||||
}
|
}
|
||||||
@ -202,10 +202,10 @@ void spSkin_addSkin(spSkin *self, const spSkin *other) {
|
|||||||
spPathConstraintDataArray_add(self->pathConstraints, other->pathConstraints->items[i]);
|
spPathConstraintDataArray_add(self->pathConstraints, other->pathConstraints->items[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < other->physicsConstraints->size; i++) {
|
for (i = 0; i < other->physicsConstraints->size; i++) {
|
||||||
if (!spPhysicsConstraintDataArray_contains(self->physicsConstraints, other->physicsConstraints->items[i]))
|
if (!spPhysicsConstraintDataArray_contains(self->physicsConstraints, other->physicsConstraints->items[i]))
|
||||||
spPhysicsConstraintDataArray_add(self->physicsConstraints, other->physicsConstraints->items[i]);
|
spPhysicsConstraintDataArray_add(self->physicsConstraints, other->physicsConstraints->items[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = spSkin_getAttachments(other);
|
entry = spSkin_getAttachments(other);
|
||||||
while (entry) {
|
while (entry) {
|
||||||
@ -238,10 +238,10 @@ void spSkin_copySkin(spSkin *self, const spSkin *other) {
|
|||||||
spPathConstraintDataArray_add(self->pathConstraints, other->pathConstraints->items[i]);
|
spPathConstraintDataArray_add(self->pathConstraints, other->pathConstraints->items[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < other->physicsConstraints->size; i++) {
|
for (i = 0; i < other->physicsConstraints->size; i++) {
|
||||||
if (!spPhysicsConstraintDataArray_contains(self->physicsConstraints, other->physicsConstraints->items[i]))
|
if (!spPhysicsConstraintDataArray_contains(self->physicsConstraints, other->physicsConstraints->items[i]))
|
||||||
spPhysicsConstraintDataArray_add(self->physicsConstraints, other->physicsConstraints->items[i]);
|
spPhysicsConstraintDataArray_add(self->physicsConstraints, other->physicsConstraints->items[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = spSkin_getAttachments(other);
|
entry = spSkin_getAttachments(other);
|
||||||
while (entry) {
|
while (entry) {
|
||||||
@ -293,5 +293,5 @@ void spSkin_clear(spSkin *self) {
|
|||||||
spIkConstraintDataArray_clear(self->ikConstraints);
|
spIkConstraintDataArray_clear(self->ikConstraints);
|
||||||
spTransformConstraintDataArray_clear(self->transformConstraints);
|
spTransformConstraintDataArray_clear(self->transformConstraints);
|
||||||
spPathConstraintDataArray_clear(self->pathConstraints);
|
spPathConstraintDataArray_clear(self->pathConstraints);
|
||||||
spPhysicsConstraintDataArray_clear(self->physicsConstraints);
|
spPhysicsConstraintDataArray_clear(self->physicsConstraints);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,7 +80,7 @@ void spSlot_setToSetupPose(spSlot *self) {
|
|||||||
else {
|
else {
|
||||||
spAttachment *attachment = spSkeleton_getAttachmentForSlotIndex(
|
spAttachment *attachment = spSkeleton_getAttachmentForSlotIndex(
|
||||||
self->bone->skeleton, self->data->index, self->data->attachmentName);
|
self->bone->skeleton, self->data->index, self->data->attachmentName);
|
||||||
self->attachment = 0;
|
self->attachment = 0;
|
||||||
spSlot_setAttachment(self, attachment);
|
spSlot_setAttachment(self, attachment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ spSlotData *spSlotData_create(const int index, const char *name, spBoneData *bon
|
|||||||
MALLOC_STR(self->name, name);
|
MALLOC_STR(self->name, name);
|
||||||
self->boneData = boneData;
|
self->boneData = boneData;
|
||||||
spColor_setFromFloats(&self->color, 1, 1, 1, 1);
|
spColor_setFromFloats(&self->color, 1, 1, 1, 1);
|
||||||
self->visible = -1;
|
self->visible = -1;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -193,8 +193,8 @@ void _spTransformConstraint_applyAbsoluteLocal(spTransformConstraint *self) {
|
|||||||
rotation = bone->arotation;
|
rotation = bone->arotation;
|
||||||
if (mixRotate != 0) {
|
if (mixRotate != 0) {
|
||||||
r = target->arotation - rotation + self->data->offsetRotation;
|
r = target->arotation - rotation + self->data->offsetRotation;
|
||||||
r -= CEIL(r / 360 - 0.5) * 360;
|
r -= CEIL(r / 360 - 0.5) * 360;
|
||||||
rotation += r * mixRotate;
|
rotation += r * mixRotate;
|
||||||
}
|
}
|
||||||
|
|
||||||
x = bone->ax, y = bone->ay;
|
x = bone->ax, y = bone->ay;
|
||||||
@ -210,8 +210,8 @@ void _spTransformConstraint_applyAbsoluteLocal(spTransformConstraint *self) {
|
|||||||
shearY = bone->ashearY;
|
shearY = bone->ashearY;
|
||||||
if (mixShearY != 0) {
|
if (mixShearY != 0) {
|
||||||
r = target->ashearY - shearY + self->data->offsetShearY;
|
r = target->ashearY - shearY + self->data->offsetShearY;
|
||||||
r -= CEIL(r / 360 - 0.5) * 360;
|
r -= CEIL(r / 360 - 0.5) * 360;
|
||||||
shearY += r * mixShearY;
|
shearY += r * mixShearY;
|
||||||
}
|
}
|
||||||
|
|
||||||
spBone_updateWorldTransformWith(bone, x, y, rotation, scaleX, scaleY, bone->ashearX, shearY);
|
spBone_updateWorldTransformWith(bone, x, y, rotation, scaleX, scaleY, bone->ashearX, shearY);
|
||||||
@ -259,11 +259,11 @@ void spTransformConstraint_update(spTransformConstraint *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spTransformConstraint_setToSetupPose(spTransformConstraint *self) {
|
void spTransformConstraint_setToSetupPose(spTransformConstraint *self) {
|
||||||
spTransformConstraintData *data = self->data;
|
spTransformConstraintData *data = self->data;
|
||||||
self->mixRotate = data->mixRotate;
|
self->mixRotate = data->mixRotate;
|
||||||
self->mixX = data->mixX;
|
self->mixX = data->mixX;
|
||||||
self->mixY = data->mixY;
|
self->mixY = data->mixY;
|
||||||
self->mixScaleX = data->mixScaleX;
|
self->mixScaleX = data->mixScaleX;
|
||||||
self->mixScaleY = data->mixScaleY;
|
self->mixScaleY = data->mixScaleY;
|
||||||
self->mixShearY = data->mixShearY;
|
self->mixShearY = data->mixShearY;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
#include "SpineSprite.h"
|
#include "SpineSprite.h"
|
||||||
|
|
||||||
void SpineSkeleton::_bind_methods() {
|
void SpineSkeleton::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("update_world_transform"), &SpineSkeleton::update_world_transform);
|
ClassDB::bind_method(D_METHOD("update_world_transform", "physics"), &SpineSkeleton::update_world_transform);
|
||||||
ClassDB::bind_method(D_METHOD("set_to_setup_pose"), &SpineSkeleton::set_to_setup_pose);
|
ClassDB::bind_method(D_METHOD("set_to_setup_pose"), &SpineSkeleton::set_to_setup_pose);
|
||||||
ClassDB::bind_method(D_METHOD("set_bones_to_setup_pose"), &SpineSkeleton::set_bones_to_setup_pose);
|
ClassDB::bind_method(D_METHOD("set_bones_to_setup_pose"), &SpineSkeleton::set_bones_to_setup_pose);
|
||||||
ClassDB::bind_method(D_METHOD("set_slots_to_setup_pose"), &SpineSkeleton::set_slots_to_setup_pose);
|
ClassDB::bind_method(D_METHOD("set_slots_to_setup_pose"), &SpineSkeleton::set_slots_to_setup_pose);
|
||||||
|
|||||||
@ -649,146 +649,146 @@ void testMixAndMatch(spSkeletonData *skeletonData, spAtlas *atlas) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cloudpot(spSkeletonData *skeletonData, spAtlas *atlas) {
|
void cloudpot(spSkeletonData *skeletonData, spAtlas *atlas) {
|
||||||
UNUSED(atlas);
|
UNUSED(atlas);
|
||||||
|
|
||||||
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
|
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
|
||||||
drawable->timeScale = 1;
|
drawable->timeScale = 1;
|
||||||
drawable->setUsePremultipliedAlpha(true);
|
drawable->setUsePremultipliedAlpha(true);
|
||||||
|
|
||||||
spSkeleton *skeleton = drawable->skeleton;
|
spSkeleton *skeleton = drawable->skeleton;
|
||||||
skeleton->x = 320;
|
skeleton->x = 320;
|
||||||
skeleton->y = 480;
|
skeleton->y = 480;
|
||||||
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
|
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
|
||||||
spAnimationState_setAnimationByName(drawable->state, 0, "playing-in-the-rain", true);
|
spAnimationState_setAnimationByName(drawable->state, 0, "playing-in-the-rain", true);
|
||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - cloudpot");
|
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - cloudpot");
|
||||||
window.setFramerateLimit(60);
|
window.setFramerateLimit(60);
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
sf::Clock deltaClock;
|
sf::Clock deltaClock;
|
||||||
|
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
while (window.pollEvent(event))
|
while (window.pollEvent(event))
|
||||||
if (event.type == sf::Event::Closed) window.close();
|
if (event.type == sf::Event::Closed) window.close();
|
||||||
|
|
||||||
float delta = deltaClock.getElapsedTime().asSeconds();
|
float delta = deltaClock.getElapsedTime().asSeconds();
|
||||||
deltaClock.restart();
|
deltaClock.restart();
|
||||||
|
|
||||||
drawable->update(delta, SP_PHYSICS_UPDATE);
|
drawable->update(delta, SP_PHYSICS_UPDATE);
|
||||||
|
|
||||||
window.clear();
|
window.clear();
|
||||||
window.draw(*drawable);
|
window.draw(*drawable);
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sack(spSkeletonData *skeletonData, spAtlas *atlas) {
|
void sack(spSkeletonData *skeletonData, spAtlas *atlas) {
|
||||||
UNUSED(atlas);
|
UNUSED(atlas);
|
||||||
|
|
||||||
|
|
||||||
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
|
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
|
||||||
drawable->timeScale = 1;
|
drawable->timeScale = 1;
|
||||||
drawable->setUsePremultipliedAlpha(true);
|
drawable->setUsePremultipliedAlpha(true);
|
||||||
|
|
||||||
spSkeleton *skeleton = drawable->skeleton;
|
spSkeleton *skeleton = drawable->skeleton;
|
||||||
skeleton->x = 320;
|
skeleton->x = 320;
|
||||||
skeleton->y = 480;
|
skeleton->y = 480;
|
||||||
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
|
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
|
||||||
spAnimationState_setAnimationByName(drawable->state, 0, "walk", true);
|
spAnimationState_setAnimationByName(drawable->state, 0, "walk", true);
|
||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - sack");
|
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - sack");
|
||||||
window.setFramerateLimit(60);
|
window.setFramerateLimit(60);
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
sf::Clock deltaClock;
|
sf::Clock deltaClock;
|
||||||
|
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
while (window.pollEvent(event))
|
while (window.pollEvent(event))
|
||||||
if (event.type == sf::Event::Closed) window.close();
|
if (event.type == sf::Event::Closed) window.close();
|
||||||
|
|
||||||
float delta = deltaClock.getElapsedTime().asSeconds();
|
float delta = deltaClock.getElapsedTime().asSeconds();
|
||||||
deltaClock.restart();
|
deltaClock.restart();
|
||||||
|
|
||||||
drawable->update(delta, SP_PHYSICS_UPDATE);
|
drawable->update(delta, SP_PHYSICS_UPDATE);
|
||||||
|
|
||||||
window.clear();
|
window.clear();
|
||||||
window.draw(*drawable);
|
window.draw(*drawable);
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void snowglobe(spSkeletonData *skeletonData, spAtlas *atlas) {
|
void snowglobe(spSkeletonData *skeletonData, spAtlas *atlas) {
|
||||||
UNUSED(atlas);
|
UNUSED(atlas);
|
||||||
|
|
||||||
|
|
||||||
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
|
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
|
||||||
drawable->timeScale = 1;
|
drawable->timeScale = 1;
|
||||||
drawable->setUsePremultipliedAlpha(true);
|
drawable->setUsePremultipliedAlpha(true);
|
||||||
|
|
||||||
spSkeleton *skeleton = drawable->skeleton;
|
spSkeleton *skeleton = drawable->skeleton;
|
||||||
skeleton->x = 320;
|
skeleton->x = 320;
|
||||||
skeleton->y = 480;
|
skeleton->y = 480;
|
||||||
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
|
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
|
||||||
spAnimationState_setAnimationByName(drawable->state, 0, "shake", true);
|
spAnimationState_setAnimationByName(drawable->state, 0, "shake", true);
|
||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - snowglobe");
|
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - snowglobe");
|
||||||
window.setFramerateLimit(60);
|
window.setFramerateLimit(60);
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
sf::Clock deltaClock;
|
sf::Clock deltaClock;
|
||||||
|
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
while (window.pollEvent(event))
|
while (window.pollEvent(event))
|
||||||
if (event.type == sf::Event::Closed) window.close();
|
if (event.type == sf::Event::Closed) window.close();
|
||||||
|
|
||||||
float delta = deltaClock.getElapsedTime().asSeconds();
|
float delta = deltaClock.getElapsedTime().asSeconds();
|
||||||
deltaClock.restart();
|
deltaClock.restart();
|
||||||
|
|
||||||
drawable->update(delta, SP_PHYSICS_UPDATE);
|
drawable->update(delta, SP_PHYSICS_UPDATE);
|
||||||
|
|
||||||
window.clear();
|
window.clear();
|
||||||
window.draw(*drawable);
|
window.draw(*drawable);
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void celestialCircus(spSkeletonData *skeletonData, spAtlas *atlas) {
|
void celestialCircus(spSkeletonData *skeletonData, spAtlas *atlas) {
|
||||||
UNUSED(atlas);
|
UNUSED(atlas);
|
||||||
|
|
||||||
|
|
||||||
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
|
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
|
||||||
drawable->timeScale = 1;
|
drawable->timeScale = 1;
|
||||||
drawable->setUsePremultipliedAlpha(true);
|
drawable->setUsePremultipliedAlpha(true);
|
||||||
|
|
||||||
spSkeleton *skeleton = drawable->skeleton;
|
spSkeleton *skeleton = drawable->skeleton;
|
||||||
skeleton->x = 320;
|
skeleton->x = 320;
|
||||||
skeleton->y = 480;
|
skeleton->y = 480;
|
||||||
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
|
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
|
||||||
spAnimationState_setAnimationByName(drawable->state, 0, "swing", true);
|
spAnimationState_setAnimationByName(drawable->state, 0, "swing", true);
|
||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - celestrial circus");
|
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - celestrial circus");
|
||||||
window.setFramerateLimit(60);
|
window.setFramerateLimit(60);
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
sf::Clock deltaClock;
|
sf::Clock deltaClock;
|
||||||
|
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
while (window.pollEvent(event))
|
while (window.pollEvent(event))
|
||||||
if (event.type == sf::Event::Closed) window.close();
|
if (event.type == sf::Event::Closed) window.close();
|
||||||
|
|
||||||
float delta = deltaClock.getElapsedTime().asSeconds();
|
float delta = deltaClock.getElapsedTime().asSeconds();
|
||||||
deltaClock.restart();
|
deltaClock.restart();
|
||||||
|
|
||||||
drawable->update(delta, SP_PHYSICS_UPDATE);
|
drawable->update(delta, SP_PHYSICS_UPDATE);
|
||||||
|
|
||||||
window.clear();
|
window.clear();
|
||||||
window.draw(*drawable);
|
window.draw(*drawable);
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
testcase(cloudpot, "data/cloud-pot.json", "data/cloud-pot.skel", "data/cloud-pot-pma.atlas", 0.2);
|
testcase(cloudpot, "data/cloud-pot.json", "data/cloud-pot.skel", "data/cloud-pot-pma.atlas", 0.2);
|
||||||
testcase(sack, "data/sack-pro.json", "data/sack-pro.skel", "data/sack-pma.atlas", 0.2f);
|
testcase(sack, "data/sack-pro.json", "data/sack-pro.skel", "data/sack-pma.atlas", 0.2f);
|
||||||
testcase(celestialCircus, "data/celestial-circus-pro.json", "data/celestial-circus-pro.skel", "data/celestial-circus-pma.atlas", 0.2f);
|
testcase(celestialCircus, "data/celestial-circus-pro.json", "data/celestial-circus-pro.skel", "data/celestial-circus-pma.atlas", 0.2f);
|
||||||
testcase(snowglobe, "data/snowglobe-pro.json", "data/snowglobe-pro.skel", "data/snowglobe-pma.atlas", 0.2f);
|
testcase(snowglobe, "data/snowglobe-pro.json", "data/snowglobe-pro.skel", "data/snowglobe-pma.atlas", 0.2f);
|
||||||
testcase(raptor, "data/raptor-pro.json", "data/raptor-pro.skel", "data/raptor-pma.atlas", 0.5f);
|
testcase(raptor, "data/raptor-pro.json", "data/raptor-pro.skel", "data/raptor-pma.atlas", 0.5f);
|
||||||
testcase(dragon, "data/dragon-ess.json", "data/dragon-ess.skel", "data/dragon-pma.atlas", 0.6f);
|
testcase(dragon, "data/dragon-ess.json", "data/dragon-ess.skel", "data/dragon-pma.atlas", 0.6f);
|
||||||
testcase(ikDemo, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.6f);
|
testcase(ikDemo, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.6f);
|
||||||
testcase(spineboy, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.6f);
|
testcase(spineboy, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.6f);
|
||||||
|
|||||||
@ -152,7 +152,7 @@ namespace spine {
|
|||||||
void SkeletonDrawable::update(float deltaTime, spPhysics physics) {
|
void SkeletonDrawable::update(float deltaTime, spPhysics physics) {
|
||||||
spAnimationState_update(state, deltaTime * timeScale);
|
spAnimationState_update(state, deltaTime * timeScale);
|
||||||
spAnimationState_apply(state, skeleton);
|
spAnimationState_apply(state, skeleton);
|
||||||
spSkeleton_update(skeleton, deltaTime * timeScale);
|
spSkeleton_update(skeleton, deltaTime * timeScale);
|
||||||
spSkeleton_updateWorldTransform(skeleton, physics);
|
spSkeleton_updateWorldTransform(skeleton, physics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -775,7 +775,7 @@ int main() {
|
|||||||
testcase(sack, "data/sack-pro.json", "data/sack-pro.skel", "data/sack-pma.atlas", 0.2f);
|
testcase(sack, "data/sack-pro.json", "data/sack-pro.skel", "data/sack-pma.atlas", 0.2f);
|
||||||
testcase(celestialCircus, "data/celestial-circus-pro.json", "data/celestial-circus-pro.skel", "data/celestial-circus-pma.atlas", 0.2f);
|
testcase(celestialCircus, "data/celestial-circus-pro.json", "data/celestial-circus-pro.skel", "data/celestial-circus-pma.atlas", 0.2f);
|
||||||
testcase(snowglobe, "data/snowglobe-pro.json", "data/snowglobe-pro.skel", "data/snowglobe-pma.atlas", 0.2f);
|
testcase(snowglobe, "data/snowglobe-pro.json", "data/snowglobe-pro.skel", "data/snowglobe-pma.atlas", 0.2f);
|
||||||
testcase(dragon, "data/dragon-ess.json", "data/dragon-ess.skel", "data/dragon-pma.atlas", 0.6f);
|
testcase(dragon, "data/dragon-ess.json", "data/dragon-ess.skel", "data/dragon-pma.atlas", 0.6f);
|
||||||
testcase(spineboy, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.62f);
|
testcase(spineboy, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.62f);
|
||||||
testcase(ikDemo, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.6f);
|
testcase(ikDemo, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.6f);
|
||||||
testcase(vine, "data/vine-pro.json", "data/vine-pro.skel", "data/vine-pma.atlas", 0.5f);
|
testcase(vine, "data/vine-pro.json", "data/vine-pro.skel", "data/vine-pma.atlas", 0.5f);
|
||||||
|
|||||||
@ -8,11 +8,15 @@ up into multiple modules:
|
|||||||
1. `spine-canvas/`, a self-contained Canvas backend, built on the core classes.
|
1. `spine-canvas/`, a self-contained Canvas backend, built on the core classes.
|
||||||
1. `spine-threejs/`, a self-contained THREE.JS backend, built on the core classes.
|
1. `spine-threejs/`, a self-contained THREE.JS backend, built on the core classes.
|
||||||
1. `spine-player/`, a self-contained player to easily display Spine animations on your website, built on the core classes and WebGL backend.
|
1. `spine-player/`, a self-contained player to easily display Spine animations on your website, built on the core classes and WebGL backend.
|
||||||
|
1. `spine-phaser/`, a Phaser backend, built on the core classes.
|
||||||
|
1. `spine-pixi/`, a Pixi backend, built on the core classes.
|
||||||
|
|
||||||
In most cases, the `spine-player` module is best suited for your needs. Please refer to the [Spine Web Player documentation](https://esotericsoftware.com/spine-player) for more information.
|
In most cases, the `spine-player` module is best suited for your needs. Please refer to the [Spine Web Player documentation](https://esotericsoftware.com/spine-player) for more information.
|
||||||
|
|
||||||
For documentation of the core API in `spine-core`, please refer to our [Spine Runtimes Guide](http://esotericsoftware.com/spine-runtimes-guide).
|
For documentation of the core API in `spine-core`, please refer to our [Spine Runtimes Guide](http://esotericsoftware.com/spine-runtimes-guide).
|
||||||
|
|
||||||
|
For documentation of spine-phaser, please refer to our [spine-phaser Guide](https://esotericsoftware.com/spine-phaser).
|
||||||
|
|
||||||
For module specific APIs in `spine-canvas`, `spine-webgl`, and `spine-threejs`, please refer to the [Examples](#examples) in the respecitve `spine-<modulename>/example` folder. For `spine-webgl` specifically, we have provided additional [demos](spine-webgl/demos), which you can also [view online](http://esotericsoftware.com/spine-demos).
|
For module specific APIs in `spine-canvas`, `spine-webgl`, and `spine-threejs`, please refer to the [Examples](#examples) in the respecitve `spine-<modulename>/example` folder. For `spine-webgl` specifically, we have provided additional [demos](spine-webgl/demos), which you can also [view online](http://esotericsoftware.com/spine-demos).
|
||||||
|
|
||||||
## Licensing
|
## Licensing
|
||||||
@ -45,20 +49,26 @@ You can include a module in your project via a `<script>` tag from the [unpkg](h
|
|||||||
|
|
||||||
```
|
```
|
||||||
// spine-ts Core
|
// spine-ts Core
|
||||||
<script src="https://unpkg.com/@esotericsoftware/spine-core@4.0.*/dist/iife/spine-core.js"></script>
|
<script src="https://unpkg.com/@esotericsoftware/spine-core@4.2.*/dist/iife/spine-core.js"></script>
|
||||||
|
|
||||||
// spine-ts Canvas
|
// spine-ts Canvas
|
||||||
<script src="https://unpkg.com/@esotericsoftware/spine-canvas@4.0.*/dist/iife/spine-canvas.js"></script>
|
<script src="https://unpkg.com/@esotericsoftware/spine-canvas@4.2.*/dist/iife/spine-canvas.js"></script>
|
||||||
|
|
||||||
// spine-ts WebGL
|
// spine-ts WebGL
|
||||||
<script src="https://unpkg.com/@esotericsoftware/spine-webgl@4.0.*/dist/iife/spine-webgl.js"></script>
|
<script src="https://unpkg.com/@esotericsoftware/spine-webgl@4.2.*/dist/iife/spine-webgl.js"></script>
|
||||||
|
|
||||||
// spine-ts Player, which requires a spine-player.css as well
|
// spine-ts Player, which requires a spine-player.css as well
|
||||||
<script src="https://unpkg.com/@esotericsoftware/spine-player@4.0.*/dist/iife/spine-player.js"></script>
|
<script src="https://unpkg.com/@esotericsoftware/spine-player@4.2.*/dist/iife/spine-player.js"></script>
|
||||||
<link rel="stylesheet" href="https://unpkg.com/@esotericsoftware/spine-player@4.0.*/dist/spine-player.css">
|
<link rel="stylesheet" href="https://unpkg.com/@esotericsoftware/spine-player@4.0.*/dist/spine-player.css">
|
||||||
|
|
||||||
// spine-ts ThreeJS
|
// spine-ts ThreeJS
|
||||||
<script src="https://unpkg.com/@esotericsoftware/spine-threejs@4.0.*/dist/iife/spine-threejs.js"></script>
|
<script src="https://unpkg.com/@esotericsoftware/spine-threejs@4.2.*/dist/iife/spine-threejs.js"></script>
|
||||||
|
|
||||||
|
// spine-phaser
|
||||||
|
<script src="https://unpkg.com/@esotericsoftware/spine-phaser@4.2.*/dist/iife/spine-phaser.js"></script>
|
||||||
|
|
||||||
|
// spine-pixi
|
||||||
|
<script src="https://unpkg.com/@esotericsoftware/spine-pixi@4.2.*/dist/iife/spine-pixi.js"></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
We also provide `js.map` source maps. They will be automatically fetched from unpkg when debugging code of a spine-module in Chrome, Firefox, or Safari, mapping the JavaScript code back to its original TypeScript sources.
|
We also provide `js.map` source maps. They will be automatically fetched from unpkg when debugging code of a spine-module in Chrome, Firefox, or Safari, mapping the JavaScript code back to its original TypeScript sources.
|
||||||
@ -75,6 +85,8 @@ npm install @esotericsoftware/spine-canvas
|
|||||||
npm install @esotericsoftware/spine-webgl
|
npm install @esotericsoftware/spine-webgl
|
||||||
npm install @esotericsoftware/spine-player
|
npm install @esotericsoftware/spine-player
|
||||||
npm install @esotericsoftware/spine-threejs
|
npm install @esotericsoftware/spine-threejs
|
||||||
|
npm install @esotericsoftware/spine-phaser
|
||||||
|
npm install @esotericsoftware/spine-pixi
|
||||||
```
|
```
|
||||||
|
|
||||||
spine-ts modules are provided in the [ECMAScript format](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), which can be consumed natively by all modern browsers, or bundled by tools like [webpack](https://webpack.js.org/), [Babel](https://babeljs.io/), [Parcel](https://parceljs.org/), or [esbuild](https://esbuild.github.io/). You can import functions and classes from a spine-ts module in your JavaScript or TypeScript code using the `import` syntax to get access to all exported constants, functions, and classes of a module:
|
spine-ts modules are provided in the [ECMAScript format](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), which can be consumed natively by all modern browsers, or bundled by tools like [webpack](https://webpack.js.org/), [Babel](https://babeljs.io/), [Parcel](https://parceljs.org/), or [esbuild](https://esbuild.github.io/). You can import functions and classes from a spine-ts module in your JavaScript or TypeScript code using the `import` syntax to get access to all exported constants, functions, and classes of a module:
|
||||||
|
|||||||
@ -138,6 +138,7 @@ export class SkeletonMesh extends THREE.Object3D {
|
|||||||
|
|
||||||
state.update(deltaTime);
|
state.update(deltaTime);
|
||||||
state.apply(skeleton);
|
state.apply(skeleton);
|
||||||
|
skeleton.update(deltaTime);
|
||||||
skeleton.updateWorldTransform(Physics.update);
|
skeleton.updateWorldTransform(Physics.update);
|
||||||
|
|
||||||
this.updateGeometry();
|
this.updateGeometry();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user