Merge branch '4.1' into 4.2-beta

This commit is contained in:
Mario Zechner 2023-02-27 13:44:34 +01:00
commit 4a66ced952
3 changed files with 208 additions and 205 deletions

View File

@ -1354,220 +1354,221 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
skeletonData->skins[skeletonData->skinsCount++] = skin;
if (strcmp(skin->name, "default") == 0) skeletonData->defaultSkin = skin;
for (attachmentsMap = Json_getItem(skinMap,
"attachments")
->child;
attachmentsMap; attachmentsMap = attachmentsMap->next) {
spSlotData *slot = spSkeletonData_findSlot(skeletonData, attachmentsMap->name);
Json *attachmentMap;
skinPart = Json_getItem(skinMap, "attachments");
if (skinPart) {
for (attachmentsMap = skinPart->child; attachmentsMap; attachmentsMap = attachmentsMap->next) {
spSlotData *slot = spSkeletonData_findSlot(skeletonData, attachmentsMap->name);
Json *attachmentMap;
for (attachmentMap = attachmentsMap->child; attachmentMap; attachmentMap = attachmentMap->next) {
spAttachment *attachment;
const char *skinAttachmentName = attachmentMap->name;
const char *attachmentName = Json_getString(attachmentMap, "name", skinAttachmentName);
const char *path = Json_getString(attachmentMap, "path", attachmentName);
const char *color;
Json *entry;
spSequence *sequence;
for (attachmentMap = attachmentsMap->child; attachmentMap; attachmentMap = attachmentMap->next) {
spAttachment *attachment;
const char *skinAttachmentName = attachmentMap->name;
const char *attachmentName = Json_getString(attachmentMap, "name", skinAttachmentName);
const char *path = Json_getString(attachmentMap, "path", attachmentName);
const char *color;
Json *entry;
spSequence *sequence;
const char *typeString = Json_getString(attachmentMap, "type", "region");
spAttachmentType type;
if (strcmp(typeString, "region") == 0) type = SP_ATTACHMENT_REGION;
else if (strcmp(typeString, "mesh") == 0)
type = SP_ATTACHMENT_MESH;
else if (strcmp(typeString, "linkedmesh") == 0)
type = SP_ATTACHMENT_LINKED_MESH;
else if (strcmp(typeString, "boundingbox") == 0)
type = SP_ATTACHMENT_BOUNDING_BOX;
else if (strcmp(typeString, "path") == 0)
type = SP_ATTACHMENT_PATH;
else if (strcmp(typeString, "clipping") == 0)
type = SP_ATTACHMENT_CLIPPING;
else if (strcmp(typeString, "point") == 0)
type = SP_ATTACHMENT_POINT;
else {
spSkeletonData_dispose(skeletonData);
_spSkeletonJson_setError(self, root, "Unknown attachment type: ", typeString);
return NULL;
}
sequence = readSequence(Json_getItem(attachmentMap, "sequence"));
attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, attachmentName,
path, sequence);
if (!attachment) {
if (self->attachmentLoader->error1) {
const char *typeString = Json_getString(attachmentMap, "type", "region");
spAttachmentType type;
if (strcmp(typeString, "region") == 0) type = SP_ATTACHMENT_REGION;
else if (strcmp(typeString, "mesh") == 0)
type = SP_ATTACHMENT_MESH;
else if (strcmp(typeString, "linkedmesh") == 0)
type = SP_ATTACHMENT_LINKED_MESH;
else if (strcmp(typeString, "boundingbox") == 0)
type = SP_ATTACHMENT_BOUNDING_BOX;
else if (strcmp(typeString, "path") == 0)
type = SP_ATTACHMENT_PATH;
else if (strcmp(typeString, "clipping") == 0)
type = SP_ATTACHMENT_CLIPPING;
else if (strcmp(typeString, "point") == 0)
type = SP_ATTACHMENT_POINT;
else {
spSkeletonData_dispose(skeletonData);
_spSkeletonJson_setError(self, root, self->attachmentLoader->error1,
self->attachmentLoader->error2);
_spSkeletonJson_setError(self, root, "Unknown attachment type: ", typeString);
return NULL;
}
continue;
}
switch (attachment->type) {
case SP_ATTACHMENT_REGION: {
spRegionAttachment *region = SUB_CAST(spRegionAttachment, attachment);
if (path) MALLOC_STR(region->path, path);
region->x = Json_getFloat(attachmentMap, "x", 0) * self->scale;
region->y = Json_getFloat(attachmentMap, "y", 0) * self->scale;
region->scaleX = Json_getFloat(attachmentMap, "scaleX", 1);
region->scaleY = Json_getFloat(attachmentMap, "scaleY", 1);
region->rotation = Json_getFloat(attachmentMap, "rotation", 0);
region->width = Json_getFloat(attachmentMap, "width", 32) * self->scale;
region->height = Json_getFloat(attachmentMap, "height", 32) * self->scale;
region->sequence = sequence;
color = Json_getString(attachmentMap, "color", 0);
if (color) {
spColor_setFromFloats(&region->color,
toColor(color, 0),
toColor(color, 1),
toColor(color, 2),
toColor(color, 3));
sequence = readSequence(Json_getItem(attachmentMap, "sequence"));
attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type,
attachmentName,
path, sequence);
if (!attachment) {
if (self->attachmentLoader->error1) {
spSkeletonData_dispose(skeletonData);
_spSkeletonJson_setError(self, root, self->attachmentLoader->error1,
self->attachmentLoader->error2);
return NULL;
}
if (region->region != NULL) spRegionAttachment_updateRegion(region);
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
break;
continue;
}
case SP_ATTACHMENT_MESH:
case SP_ATTACHMENT_LINKED_MESH: {
spMeshAttachment *mesh = SUB_CAST(spMeshAttachment, attachment);
MALLOC_STR(mesh->path, path);
switch (attachment->type) {
case SP_ATTACHMENT_REGION: {
spRegionAttachment *region = SUB_CAST(spRegionAttachment, attachment);
if (path) MALLOC_STR(region->path, path);
region->x = Json_getFloat(attachmentMap, "x", 0) * self->scale;
region->y = Json_getFloat(attachmentMap, "y", 0) * self->scale;
region->scaleX = Json_getFloat(attachmentMap, "scaleX", 1);
region->scaleY = Json_getFloat(attachmentMap, "scaleY", 1);
region->rotation = Json_getFloat(attachmentMap, "rotation", 0);
region->width = Json_getFloat(attachmentMap, "width", 32) * self->scale;
region->height = Json_getFloat(attachmentMap, "height", 32) * self->scale;
region->sequence = sequence;
color = Json_getString(attachmentMap, "color", 0);
if (color) {
spColor_setFromFloats(&mesh->color,
toColor(color, 0),
toColor(color, 1),
toColor(color, 2),
toColor(color, 3));
}
mesh->width = Json_getFloat(attachmentMap, "width", 32) * self->scale;
mesh->height = Json_getFloat(attachmentMap, "height", 32) * self->scale;
mesh->sequence = sequence;
entry = Json_getItem(attachmentMap, "parent");
if (!entry) {
int verticesLength;
entry = Json_getItem(attachmentMap, "triangles");
mesh->trianglesCount = entry->size;
mesh->triangles = MALLOC(unsigned short, entry->size);
for (entry = entry->child, ii = 0; entry; entry = entry->next, ++ii)
mesh->triangles[ii] = (unsigned short) entry->valueInt;
entry = Json_getItem(attachmentMap, "uvs");
verticesLength = entry->size;
mesh->regionUVs = MALLOC(float, verticesLength);
for (entry = entry->child, ii = 0; entry; entry = entry->next, ++ii)
mesh->regionUVs[ii] = entry->valueFloat;
_readVertices(self, attachmentMap, SUPER(mesh), verticesLength);
if (mesh->region != NULL) spMeshAttachment_updateRegion(mesh);
mesh->hullLength = Json_getInt(attachmentMap, "hull", 0);
entry = Json_getItem(attachmentMap, "edges");
if (entry) {
mesh->edgesCount = entry->size;
mesh->edges = MALLOC(int, entry->size);
for (entry = entry->child, ii = 0; entry; entry = entry->next, ++ii)
mesh->edges[ii] = entry->valueInt;
color = Json_getString(attachmentMap, "color", 0);
if (color) {
spColor_setFromFloats(&region->color,
toColor(color, 0),
toColor(color, 1),
toColor(color, 2),
toColor(color, 3));
}
if (region->region != NULL) spRegionAttachment_updateRegion(region);
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
} else {
int inheritTimelines = Json_getInt(attachmentMap, "timelines", 1);
_spSkeletonJson_addLinkedMesh(self, SUB_CAST(spMeshAttachment, attachment),
Json_getString(attachmentMap, "skin", 0), slot->index,
entry->valueString, inheritTimelines);
break;
}
break;
}
case SP_ATTACHMENT_BOUNDING_BOX: {
spBoundingBoxAttachment *box = SUB_CAST(spBoundingBoxAttachment, attachment);
int vertexCount = Json_getInt(attachmentMap, "vertexCount", 0) << 1;
_readVertices(self, attachmentMap, SUPER(box), vertexCount);
box->super.verticesCount = vertexCount;
color = Json_getString(attachmentMap, "color", 0);
if (color) {
spColor_setFromFloats(&box->color,
toColor(color, 0),
toColor(color, 1),
toColor(color, 2),
toColor(color, 3));
}
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
break;
}
case SP_ATTACHMENT_PATH: {
spPathAttachment *pathAttachment = SUB_CAST(spPathAttachment, attachment);
int vertexCount = 0;
pathAttachment->closed = Json_getInt(attachmentMap, "closed", 0);
pathAttachment->constantSpeed = Json_getInt(attachmentMap, "constantSpeed", 1);
vertexCount = Json_getInt(attachmentMap, "vertexCount", 0);
_readVertices(self, attachmentMap, SUPER(pathAttachment), vertexCount << 1);
case SP_ATTACHMENT_MESH:
case SP_ATTACHMENT_LINKED_MESH: {
spMeshAttachment *mesh = SUB_CAST(spMeshAttachment, attachment);
pathAttachment->lengthsLength = vertexCount / 3;
pathAttachment->lengths = MALLOC(float, pathAttachment->lengthsLength);
MALLOC_STR(mesh->path, path);
curves = Json_getItem(attachmentMap, "lengths");
for (curves = curves->child, ii = 0; curves; curves = curves->next, ++ii)
pathAttachment->lengths[ii] = curves->valueFloat * self->scale;
color = Json_getString(attachmentMap, "color", 0);
if (color) {
spColor_setFromFloats(&pathAttachment->color,
toColor(color, 0),
toColor(color, 1),
toColor(color, 2),
toColor(color, 3));
}
break;
}
case SP_ATTACHMENT_POINT: {
spPointAttachment *point = SUB_CAST(spPointAttachment, attachment);
point->x = Json_getFloat(attachmentMap, "x", 0) * self->scale;
point->y = Json_getFloat(attachmentMap, "y", 0) * self->scale;
point->rotation = Json_getFloat(attachmentMap, "rotation", 0);
color = Json_getString(attachmentMap, "color", 0);
if (color) {
spColor_setFromFloats(&mesh->color,
toColor(color, 0),
toColor(color, 1),
toColor(color, 2),
toColor(color, 3));
}
color = Json_getString(attachmentMap, "color", 0);
if (color) {
spColor_setFromFloats(&point->color,
toColor(color, 0),
toColor(color, 1),
toColor(color, 2),
toColor(color, 3));
mesh->width = Json_getFloat(attachmentMap, "width", 32) * self->scale;
mesh->height = Json_getFloat(attachmentMap, "height", 32) * self->scale;
mesh->sequence = sequence;
entry = Json_getItem(attachmentMap, "parent");
if (!entry) {
int verticesLength;
entry = Json_getItem(attachmentMap, "triangles");
mesh->trianglesCount = entry->size;
mesh->triangles = MALLOC(unsigned short, entry->size);
for (entry = entry->child, ii = 0; entry; entry = entry->next, ++ii)
mesh->triangles[ii] = (unsigned short) entry->valueInt;
entry = Json_getItem(attachmentMap, "uvs");
verticesLength = entry->size;
mesh->regionUVs = MALLOC(float, verticesLength);
for (entry = entry->child, ii = 0; entry; entry = entry->next, ++ii)
mesh->regionUVs[ii] = entry->valueFloat;
_readVertices(self, attachmentMap, SUPER(mesh), verticesLength);
if (mesh->region != NULL) spMeshAttachment_updateRegion(mesh);
mesh->hullLength = Json_getInt(attachmentMap, "hull", 0);
entry = Json_getItem(attachmentMap, "edges");
if (entry) {
mesh->edgesCount = entry->size;
mesh->edges = MALLOC(int, entry->size);
for (entry = entry->child, ii = 0; entry; entry = entry->next, ++ii)
mesh->edges[ii] = entry->valueInt;
}
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
} else {
int inheritTimelines = Json_getInt(attachmentMap, "timelines", 1);
_spSkeletonJson_addLinkedMesh(self, SUB_CAST(spMeshAttachment, attachment),
Json_getString(attachmentMap, "skin", 0), slot->index,
entry->valueString, inheritTimelines);
}
break;
}
case SP_ATTACHMENT_BOUNDING_BOX: {
spBoundingBoxAttachment *box = SUB_CAST(spBoundingBoxAttachment, attachment);
int vertexCount = Json_getInt(attachmentMap, "vertexCount", 0) << 1;
_readVertices(self, attachmentMap, SUPER(box), vertexCount);
box->super.verticesCount = vertexCount;
color = Json_getString(attachmentMap, "color", 0);
if (color) {
spColor_setFromFloats(&box->color,
toColor(color, 0),
toColor(color, 1),
toColor(color, 2),
toColor(color, 3));
}
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
break;
}
case SP_ATTACHMENT_PATH: {
spPathAttachment *pathAttachment = SUB_CAST(spPathAttachment, attachment);
int vertexCount = 0;
pathAttachment->closed = Json_getInt(attachmentMap, "closed", 0);
pathAttachment->constantSpeed = Json_getInt(attachmentMap, "constantSpeed", 1);
vertexCount = Json_getInt(attachmentMap, "vertexCount", 0);
_readVertices(self, attachmentMap, SUPER(pathAttachment), vertexCount << 1);
pathAttachment->lengthsLength = vertexCount / 3;
pathAttachment->lengths = MALLOC(float, pathAttachment->lengthsLength);
curves = Json_getItem(attachmentMap, "lengths");
for (curves = curves->child, ii = 0; curves; curves = curves->next, ++ii)
pathAttachment->lengths[ii] = curves->valueFloat * self->scale;
color = Json_getString(attachmentMap, "color", 0);
if (color) {
spColor_setFromFloats(&pathAttachment->color,
toColor(color, 0),
toColor(color, 1),
toColor(color, 2),
toColor(color, 3));
}
break;
}
case SP_ATTACHMENT_POINT: {
spPointAttachment *point = SUB_CAST(spPointAttachment, attachment);
point->x = Json_getFloat(attachmentMap, "x", 0) * self->scale;
point->y = Json_getFloat(attachmentMap, "y", 0) * self->scale;
point->rotation = Json_getFloat(attachmentMap, "rotation", 0);
color = Json_getString(attachmentMap, "color", 0);
if (color) {
spColor_setFromFloats(&point->color,
toColor(color, 0),
toColor(color, 1),
toColor(color, 2),
toColor(color, 3));
}
break;
}
case SP_ATTACHMENT_CLIPPING: {
spClippingAttachment *clip = SUB_CAST(spClippingAttachment, attachment);
int vertexCount = 0;
const char *end = Json_getString(attachmentMap, "end", 0);
if (end) {
spSlotData *endSlot = spSkeletonData_findSlot(skeletonData, end);
clip->endSlot = endSlot;
}
vertexCount = Json_getInt(attachmentMap, "vertexCount", 0) << 1;
_readVertices(self, attachmentMap, SUPER(clip), vertexCount);
color = Json_getString(attachmentMap, "color", 0);
if (color) {
spColor_setFromFloats(&clip->color,
toColor(color, 0),
toColor(color, 1),
toColor(color, 2),
toColor(color, 3));
}
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
break;
}
break;
}
case SP_ATTACHMENT_CLIPPING: {
spClippingAttachment *clip = SUB_CAST(spClippingAttachment, attachment);
int vertexCount = 0;
const char *end = Json_getString(attachmentMap, "end", 0);
if (end) {
spSlotData *endSlot = spSkeletonData_findSlot(skeletonData, end);
clip->endSlot = endSlot;
}
vertexCount = Json_getInt(attachmentMap, "vertexCount", 0) << 1;
_readVertices(self, attachmentMap, SUPER(clip), vertexCount);
color = Json_getString(attachmentMap, "color", 0);
if (color) {
spColor_setFromFloats(&clip->color,
toColor(color, 0),
toColor(color, 1),
toColor(color, 2),
toColor(color, 3));
}
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
break;
}
spSkin_setAttachment(skin, slot->index, skinAttachmentName, attachment);
}
spSkin_setAttachment(skin, slot->index, skinAttachmentName, attachment);
}
}
}

View File

@ -28,7 +28,6 @@
*****************************************************************************/
#include <spine/MeshAttachment.h>
#include <spine/HasRendererObject.h>
using namespace spine;
@ -53,10 +52,13 @@ void MeshAttachment::updateRegion() {
_uvs.setSize(_regionUVs.size(), 0);
}
if (_region == nullptr) {
return;
}
int i = 0, n = (int) _regionUVs.size();
float u = _region->u, v = _region->v;
float width = 0, height = 0;
switch (_region->degrees) {
case 90: {
float textureWidth = _region->height / (_region->u2 - _region->u);

View File

@ -264,7 +264,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(USpineSkeletonComponent *compon
// ignore regions for which we can't find a material
UMaterialInstanceDynamic *material = nullptr;
int foundPageIndex = -1;
for (int pageIndex = 0; i < component->Atlas->atlasPages.Num(); pageIndex++) {
for (int pageIndex = 0; pageIndex < component->Atlas->atlasPages.Num(); pageIndex++) {
AtlasPage *page = component->Atlas->GetAtlas()->getPages()[pageIndex];
if (attachmentAtlasRegion->page == page) {
foundPageIndex = pageIndex;
@ -277,33 +277,33 @@ void USpineSkeletonRendererComponent::UpdateMesh(USpineSkeletonComponent *compon
}
switch (slot->getData().getBlendMode()) {
case BlendMode_Additive:
if (i >= atlasAdditiveBlendMaterials.Num()) {
if (foundPageIndex >= atlasAdditiveBlendMaterials.Num()) {
clipper.clipEnd(*slot);
continue;
}
material = atlasAdditiveBlendMaterials[i];
material = atlasAdditiveBlendMaterials[foundPageIndex];
break;
case BlendMode_Multiply:
if (i >= atlasMultiplyBlendMaterials.Num()) {
if (foundPageIndex >= atlasMultiplyBlendMaterials.Num()) {
clipper.clipEnd(*slot);
continue;
}
material = atlasMultiplyBlendMaterials[i];
material = atlasMultiplyBlendMaterials[foundPageIndex];
break;
case BlendMode_Screen:
if (i >= atlasScreenBlendMaterials.Num()) {
if (foundPageIndex >= atlasScreenBlendMaterials.Num()) {
clipper.clipEnd(*slot);
continue;
}
material = atlasScreenBlendMaterials[i];
material = atlasScreenBlendMaterials[foundPageIndex];
break;
case BlendMode_Normal:
default:
if (i >= atlasNormalBlendMaterials.Num()) {
if (foundPageIndex >= atlasNormalBlendMaterials.Num()) {
clipper.clipEnd(*slot);
continue;
}
material = atlasNormalBlendMaterials[i];
material = atlasNormalBlendMaterials[foundPageIndex];
break;
}