|
@@ -116,8 +116,6 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
|
|
Json* ffd = Json_getItem(root, "ffd");
|
|
Json* ffd = Json_getItem(root, "ffd");
|
|
Json* drawOrder = Json_getItem(root, "drawOrder");
|
|
Json* drawOrder = Json_getItem(root, "drawOrder");
|
|
Json* events = Json_getItem(root, "events");
|
|
Json* events = Json_getItem(root, "events");
|
|
- Json* flipX = Json_getItem(root, "flipx");
|
|
|
|
- Json* flipY = Json_getItem(root, "flipy");
|
|
|
|
Json *boneMap, *slotMap, *ikMap, *ffdMap;
|
|
Json *boneMap, *slotMap, *ikMap, *ffdMap;
|
|
if (!drawOrder) drawOrder = Json_getItem(root, "draworder");
|
|
if (!drawOrder) drawOrder = Json_getItem(root, "draworder");
|
|
|
|
|
|
@@ -131,8 +129,6 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
|
|
timelinesCount += slotMap->size;
|
|
timelinesCount += slotMap->size;
|
|
if (drawOrder) ++timelinesCount;
|
|
if (drawOrder) ++timelinesCount;
|
|
if (events) ++timelinesCount;
|
|
if (events) ++timelinesCount;
|
|
- if (flipX) ++timelinesCount;
|
|
|
|
- if (flipY) ++timelinesCount;
|
|
|
|
|
|
|
|
animation = spAnimation_create(root->name, timelinesCount);
|
|
animation = spAnimation_create(root->name, timelinesCount);
|
|
animation->timelinesCount = 0;
|
|
animation->timelinesCount = 0;
|
|
@@ -221,16 +217,6 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
|
|
animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline);
|
|
animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline);
|
|
duration = timeline->frames[timelineArray->size * 3 - 3];
|
|
duration = timeline->frames[timelineArray->size * 3 - 3];
|
|
if (duration > animation->duration) animation->duration = duration;
|
|
if (duration > animation->duration) animation->duration = duration;
|
|
- } else if (strcmp(timelineArray->name, "flipX") == 0 || strcmp(timelineArray->name, "flipY") == 0) {
|
|
|
|
- int x = strcmp(timelineArray->name, "flipX") == 0;
|
|
|
|
- const char* field = x ? "x" : "y";
|
|
|
|
- spFlipTimeline *timeline = spFlipTimeline_create(timelineArray->size, x);
|
|
|
|
- timeline->boneIndex = boneIndex;
|
|
|
|
- for (frame = timelineArray->child, i = 0; frame; frame = frame->next, ++i)
|
|
|
|
- spFlipTimeline_setFrame(timeline, i, Json_getFloat(frame, "time", 0), Json_getInt(frame, field, 0));
|
|
|
|
- animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline);
|
|
|
|
- duration = timeline->frames[timelineArray->size * 2 - 2];
|
|
|
|
- if (duration > animation->duration) animation->duration = duration;
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
spAnimation_dispose(animation);
|
|
spAnimation_dispose(animation);
|
|
@@ -281,8 +267,8 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
|
|
}
|
|
}
|
|
if (attachment->type == SP_ATTACHMENT_MESH)
|
|
if (attachment->type == SP_ATTACHMENT_MESH)
|
|
verticesCount = SUB_CAST(spMeshAttachment, attachment)->verticesCount;
|
|
verticesCount = SUB_CAST(spMeshAttachment, attachment)->verticesCount;
|
|
- else if (attachment->type == SP_ATTACHMENT_SKINNED_MESH)
|
|
|
|
- verticesCount = SUB_CAST(spSkinnedMeshAttachment, attachment)->weightsCount / 3 * 2;
|
|
|
|
|
|
+ else if (attachment->type == SP_ATTACHMENT_WEIGHTED_MESH)
|
|
|
|
+ verticesCount = SUB_CAST(spWeightedMeshAttachment, attachment)->weightsCount / 3 * 2;
|
|
|
|
|
|
timeline = spFFDTimeline_create(timelineArray->size, verticesCount);
|
|
timeline = spFFDTimeline_create(timelineArray->size, verticesCount);
|
|
timeline->slotIndex = slotIndex;
|
|
timeline->slotIndex = slotIndex;
|
|
@@ -384,18 +370,19 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
|
|
for (frame = events->child, i = 0; frame; frame = frame->next, ++i) {
|
|
for (frame = events->child, i = 0; frame; frame = frame->next, ++i) {
|
|
spEvent* event;
|
|
spEvent* event;
|
|
const char* stringValue;
|
|
const char* stringValue;
|
|
|
|
+ float time = Json_getFloat(frame, "time", 0);
|
|
spEventData* eventData = spSkeletonData_findEvent(skeletonData, Json_getString(frame, "name", 0));
|
|
spEventData* eventData = spSkeletonData_findEvent(skeletonData, Json_getString(frame, "name", 0));
|
|
if (!eventData) {
|
|
if (!eventData) {
|
|
spAnimation_dispose(animation);
|
|
spAnimation_dispose(animation);
|
|
_spSkeletonJson_setError(self, 0, "Event not found: ", Json_getString(frame, "name", 0));
|
|
_spSkeletonJson_setError(self, 0, "Event not found: ", Json_getString(frame, "name", 0));
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
- event = spEvent_create(eventData);
|
|
|
|
|
|
+ event = spEvent_create(time, eventData);
|
|
event->intValue = Json_getInt(frame, "int", eventData->intValue);
|
|
event->intValue = Json_getInt(frame, "int", eventData->intValue);
|
|
event->floatValue = Json_getFloat(frame, "float", eventData->floatValue);
|
|
event->floatValue = Json_getFloat(frame, "float", eventData->floatValue);
|
|
stringValue = Json_getString(frame, "string", eventData->stringValue);
|
|
stringValue = Json_getString(frame, "string", eventData->stringValue);
|
|
if (stringValue) MALLOC_STR(event->stringValue, stringValue);
|
|
if (stringValue) MALLOC_STR(event->stringValue, stringValue);
|
|
- spEventTimeline_setFrame(timeline, i, Json_getFloat(frame, "time", 0), event);
|
|
|
|
|
|
+ spEventTimeline_setFrame(timeline, i, time, event);
|
|
}
|
|
}
|
|
animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline);
|
|
animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline);
|
|
duration = timeline->frames[events->size - 1];
|
|
duration = timeline->frames[events->size - 1];
|
|
@@ -421,7 +408,7 @@ spSkeletonData* spSkeletonJson_readSkeletonDataFile (spSkeletonJson* self, const
|
|
spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const char* json) {
|
|
spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const char* json) {
|
|
int i, ii;
|
|
int i, ii;
|
|
spSkeletonData* skeletonData;
|
|
spSkeletonData* skeletonData;
|
|
- Json *root, *skeleton, *bones, *boneMap, *ik, *slots, *skins, *animations, *events;
|
|
|
|
|
|
+ Json *root, *skeleton, *bones, *boneMap, *ik, *transform, *slots, *skins, *animations, *events;
|
|
char* oldLocale;
|
|
char* oldLocale;
|
|
|
|
|
|
FREE(self->error);
|
|
FREE(self->error);
|
|
@@ -471,8 +458,6 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
|
|
boneData->scaleY = Json_getFloat(boneMap, "scaleY", 1);
|
|
boneData->scaleY = Json_getFloat(boneMap, "scaleY", 1);
|
|
boneData->inheritScale = Json_getInt(boneMap, "inheritScale", 1);
|
|
boneData->inheritScale = Json_getInt(boneMap, "inheritScale", 1);
|
|
boneData->inheritRotation = Json_getInt(boneMap, "inheritRotation", 1);
|
|
boneData->inheritRotation = Json_getInt(boneMap, "inheritRotation", 1);
|
|
- boneData->flipX = Json_getInt(boneMap, "flipX", 0);
|
|
|
|
- boneData->flipY = Json_getInt(boneMap, "flipY", 0);
|
|
|
|
|
|
|
|
skeletonData->bones[i] = boneData;
|
|
skeletonData->bones[i] = boneData;
|
|
skeletonData->bonesCount++;
|
|
skeletonData->bonesCount++;
|
|
@@ -515,6 +500,41 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /* Transform constraints. */
|
|
|
|
+ transform = Json_getItem(root, "transform");
|
|
|
|
+ if (transform) {
|
|
|
|
+ Json *transformMap;
|
|
|
|
+ skeletonData->transformConstraintsCount = transform->size;
|
|
|
|
+ skeletonData->transformConstraints = MALLOC(spTransformConstraintData*, transform->size);
|
|
|
|
+ for (transformMap = transform->child, i = 0; transformMap; transformMap = transformMap->next, ++i) {
|
|
|
|
+ const char* name;
|
|
|
|
+
|
|
|
|
+ spTransformConstraintData* transformConstraintData = spTransformConstraintData_create(Json_getString(transformMap, "name", 0));
|
|
|
|
+
|
|
|
|
+ name = Json_getString(transformMap, "bone", 0);
|
|
|
|
+ transformConstraintData->bone = spSkeletonData_findBone(skeletonData, name);
|
|
|
|
+ if (!transformConstraintData->bone) {
|
|
|
|
+ spSkeletonData_dispose(skeletonData);
|
|
|
|
+ _spSkeletonJson_setError(self, root, "Bone not found: ", boneMap->name);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ name = Json_getString(transformMap, "target", 0);
|
|
|
|
+ transformConstraintData->target = spSkeletonData_findBone(skeletonData, name);
|
|
|
|
+ if (!transformConstraintData->target) {
|
|
|
|
+ spSkeletonData_dispose(skeletonData);
|
|
|
|
+ _spSkeletonJson_setError(self, root, "Target bone not found: ", boneMap->name);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ transformConstraintData->translateMix = Json_getFloat(transformMap, "translateMix", 1);
|
|
|
|
+ transformConstraintData->x = Json_getFloat(transformMap, "x", 0);
|
|
|
|
+ transformConstraintData->y = Json_getFloat(transformMap, "y", 0);
|
|
|
|
+
|
|
|
|
+ skeletonData->transformConstraints[i] = transformConstraintData;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/* Slots. */
|
|
/* Slots. */
|
|
slots = Json_getItem(root, "slots");
|
|
slots = Json_getItem(root, "slots");
|
|
if (slots) {
|
|
if (slots) {
|
|
@@ -593,8 +613,8 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
|
|
type = SP_ATTACHMENT_REGION;
|
|
type = SP_ATTACHMENT_REGION;
|
|
else if (strcmp(typeString, "mesh") == 0)
|
|
else if (strcmp(typeString, "mesh") == 0)
|
|
type = SP_ATTACHMENT_MESH;
|
|
type = SP_ATTACHMENT_MESH;
|
|
- else if (strcmp(typeString, "skinnedmesh") == 0)
|
|
|
|
- type = SP_ATTACHMENT_SKINNED_MESH;
|
|
|
|
|
|
+ else if (strcmp(typeString, "weightedmesh") == 0 || strcmp(typeString, "skinnedmesh") == 0)
|
|
|
|
+ type = SP_ATTACHMENT_WEIGHTED_MESH;
|
|
else if (strcmp(typeString, "boundingbox") == 0)
|
|
else if (strcmp(typeString, "boundingbox") == 0)
|
|
type = SP_ATTACHMENT_BOUNDING_BOX;
|
|
type = SP_ATTACHMENT_BOUNDING_BOX;
|
|
else {
|
|
else {
|
|
@@ -682,8 +702,8 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
|
|
mesh->height = Json_getFloat(attachmentMap, "height", 32) * self->scale;
|
|
mesh->height = Json_getFloat(attachmentMap, "height", 32) * self->scale;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- case SP_ATTACHMENT_SKINNED_MESH: {
|
|
|
|
- spSkinnedMeshAttachment* mesh = SUB_CAST(spSkinnedMeshAttachment, attachment);
|
|
|
|
|
|
+ case SP_ATTACHMENT_WEIGHTED_MESH: {
|
|
|
|
+ spWeightedMeshAttachment* mesh = SUB_CAST(spWeightedMeshAttachment, attachment);
|
|
int verticesCount, b, w, nn;
|
|
int verticesCount, b, w, nn;
|
|
float* vertices;
|
|
float* vertices;
|
|
|
|
|
|
@@ -729,7 +749,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
|
|
for (entry = entry->child, i = 0; entry; entry = entry->next, ++i)
|
|
for (entry = entry->child, i = 0; entry; entry = entry->next, ++i)
|
|
mesh->triangles[i] = entry->valueInt;
|
|
mesh->triangles[i] = entry->valueInt;
|
|
|
|
|
|
- spSkinnedMeshAttachment_updateUVs(mesh);
|
|
|
|
|
|
+ spWeightedMeshAttachment_updateUVs(mesh);
|
|
|
|
|
|
color = Json_getString(attachmentMap, "color", 0);
|
|
color = Json_getString(attachmentMap, "color", 0);
|
|
if (color) {
|
|
if (color) {
|