void HelloWorld::changeAttachment(SpineNode* spineNode,const char *atlasAttachment, const char *replacedAttachment,const char *replaceAttachment){ spSlot* slot = spineNode->findSlot(replacedAttachment); if (NULL != slot) { int nType = slot->attachment->type; spAtlas* atlas = spAtlas_createFromFile(atlasAttachment, nullptr); CCASSERT(atlas, "SkeletonRenderer loading atlas file error"); spAtlasAttachmentLoader* atlasAttachmentLoader = spAtlasAttachmentLoader_create(atlas); spAttachmentLoader* attachmentLoader = &(atlasAttachmentLoader->super); spSkin *skin = spSkin_create("default"); spRegionAttachment* regionAttachmentSrc = (spRegionAttachment*)(slot->attachment); spAttachment* attachment = spAttachmentLoader_newAttachment( attachmentLoader, skin, SP_ATTACHMENT_REGION, replacedAttachment, replaceAttachment); spRegionAttachment* regionAttachment = (spRegionAttachment*)attachment; regionAttachment->width = regionAttachmentSrc->width; regionAttachment->height = regionAttachmentSrc->height; regionAttachment->rotation = regionAttachmentSrc->rotation; regionAttachment->x = regionAttachmentSrc->x; regionAttachment->y = regionAttachmentSrc->y; regionAttachment->scaleX = regionAttachmentSrc->scaleX; regionAttachment->scaleY = regionAttachmentSrc->scaleY; regionAttachment->a = regionAttachmentSrc->a; regionAttachment->b = regionAttachmentSrc->b; regionAttachment->r = regionAttachmentSrc->r; regionAttachment->g = regionAttachmentSrc->g; spRegionAttachment_updateOffset(regionAttachment); spineNode->replacementPart(slot,attachment); //spineNode->replacementPart("shi_01_01_01_002",attachment); } }
static spAttachment *readAttachment(spSkeletonBinary *self, spSkin *skin, int slotIndex, const char *attachmentName) { spAttachment *attachment = NULL; float scale = self->scale; char *name = readString(self); if (name == NULL) name = (char *)attachmentName; switch ((spAttachmentType)readByte(self)) { case SP_ATTACHMENT_REGION: { spRegionAttachment *region; char *path = readString(self); if (path == NULL) path = name; attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_REGION, name, path); region = SUB_CAST(spRegionAttachment, attachment); if (path) { region->path = copyString(path); } region->rotation = readFloat(self); region->x = readFloat(self) * scale; region->y = readFloat(self) * scale; region->scaleX = readFloat(self); region->scaleY = readFloat(self); region->width = readFloat(self) * scale; region->height = readFloat(self) * scale; readColor(self, ®ion->r, ®ion->g, ®ion->b, ®ion->a); spRegionAttachment_updateOffset(region); spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); break; } case SP_ATTACHMENT_BOUNDING_BOX: { spBoundingBoxAttachment *boundingBox; int vertexCount = readVarint(self, true); attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_BOUNDING_BOX, name, name); boundingBox = SUB_CAST(spBoundingBoxAttachment, attachment); readVertices(self, SUPER(boundingBox), vertexCount); SUPER(boundingBox)->worldVerticesLength = vertexCount << 1; spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); break; } case SP_ATTACHMENT_MESH: { spMeshAttachment *mesh; int vertexCount; char *path = readString(self); if (path == NULL) path = name; attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_MESH, name, path); mesh = SUB_CAST(spMeshAttachment, attachment); if (path) { mesh->path = copyString(path); } readColor(self, &mesh->r, &mesh->g, &mesh->b, &mesh->a); vertexCount = readVarint(self, true); mesh->regionUVs = readFloats(self, 1, vertexCount << 1); mesh->trianglesCount = readVarint(self, true); mesh->triangles = readShorts(self, mesh->trianglesCount); readVertices(self, SUPER(mesh), vertexCount); SUPER(mesh)->worldVerticesLength = vertexCount << 1; mesh->hullLength = readVarint(self, true) << 1; spMeshAttachment_updateUVs(mesh); spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); break; } case SP_ATTACHMENT_LINKED_MESH: { spMeshAttachment *mesh; char *parent; char *skinName; char *path = readString(self); if (path == NULL) path = name; attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_LINKED_MESH, name, path); mesh = SUB_CAST(spMeshAttachment, attachment); if (path) { mesh->path = copyString(path); } readColor(self, &mesh->r, &mesh->g, &mesh->b, &mesh->a); skinName = readString(self); parent = readString(self); mesh->inheritDeform = readBoolean(self); addLinkedMesh(self, mesh, skinName, slotIndex, parent); break; } case SP_ATTACHMENT_PATH: { spPathAttachment *path; int vertexCount; attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_PATH, name, NULL); path = SUB_CAST(spPathAttachment, attachment); path->closed = readBoolean(self); path->constantSpeed = readBoolean(self); vertexCount = readVarint(self, true); readVertices(self, SUPER(path), vertexCount); SUPER(path)->worldVerticesLength = vertexCount << 1; path->lengthsLength = vertexCount / 3; path->lengths = MALLOC(float, path->lengthsLength); for (int i = 0; i < path->lengthsLength; i++) { path->lengths[i] = readFloat(self) * self->scale; } break; } } return attachment; }