@Pharan, @Nate, @badlogic - thanks for the help! Especially the code from the pull 465 has been very helpful. I have now been able to clone a skin with shallow copies. That seems to work very well.
I have moved on to the code for cloning region attachments (starting simple). This does a deep copy, using the example from the pull 465 as well. I then add the newly cloned attachment to the skin, and set the attachment for the slot on the spine.
Everything seems to work, and my logs that get the attachment from the skin seem to indicate that the new attachment is in place, however the visual result in the game is not altered.
// generic function to clone an attachment, switch its region, and then set it as the attachment for a given slot
void cloneAndUpdateAttachment(spine::SkeletonAnimation* mSpine, spSkin* skin, string slotName, string attachmentName, string newRegion) {
// find the slot
int slotIndex = spSkeleton_findSlotIndex(mSpine->skeleton, slotName.c_str());
// find the attachment we plan to clone
spAttachment* attachment = spSkin_getAttachment(skin, slotIndex, slotName.c_str());
if(attachment != NULL) {
switch(attachment->type) {
case SP_ATTACHMENT_MESH:
case SP_ATTACHMENT_LINKED_MESH:
case SP_ATTACHMENT_WEIGHTED_MESH:
case SP_ATTACHMENT_WEIGHTED_LINKED_MESH:{
// This is a WEIGHTED MESH: so extra work to be done here
spAtlasRegion* region = spAtlas_findRegion(this->getRegionMap()->findAtlas("sprites/st2_grayman.txt"), newRegion.c_str());
if (!region) {
assert("[Combat Spine] Update standard Linked Mesh: region %s not found.", newRegion.c_str());
return;
}
// TODO: haven't implemented meshes yet, want to get region attachments working
break;
}
case SP_ATTACHMENT_REGION: {
// finding the new region (in the case of the Torso, "merchant_torso" from the atlast
spAtlasRegion* region = spAtlas_findRegion(this->getRegionMap()->findAtlas("sprites/st2_grayman.txt"), newRegion.c_str());
if (!region) {
assert("[Combat Spine] Update standard Linked Mesh: region %s not found.", newRegion.c_str());
return;
}
// start the deep clone process
const spRegionAttachment* const self = SUB_CAST(spRegionAttachment, attachment);
// name the new attachment after the new region (in the case of the Torso slot, "merchant_torso"
spRegionAttachment* const result = spRegionAttachment_create(newRegion.c_str());
MALLOC_STR(result->path, newRegion.c_str());
result->x = self->x;
result->y = self->y;
result->scaleX = self->scaleX;
result->scaleY = self->scaleY;
result->rotation = self->rotation;
result->width = self->width;
result->height = self->height;
result->r = self->r;
result->g = self->g;
result->b = self->b;
result->a = self->a;
// here, I am pointing the new attachment at the new region, merchant_torso
result->rendererObject = region;
spRegionAttachment_setUVs(result, region->u, region->v, region->u2, region->v2, region->rotate);
// rebuild the region data
result->regionOffsetX = region->offsetX;
result->regionOffsetY = region->offsetY;
result->regionWidth = region->width;
result->regionHeight = region->height;
result->regionOriginalWidth = region->originalWidth;
result->regionOriginalHeight = region->originalHeight;
// memcopy some values - copied from pull 465
memcpy( result->offset, self->offset, sizeof( result->offset ) );
memcpy( result->uvs, self->uvs, sizeof( result->offset ) );
// testing a specific slot
---
this is the slot name "Torso" at this point, the attachment name is "crew_torso"
if(slotIndex == 3) {
spAttachment* attDone = spSkin_getAttachment(skin, slotIndex, slotName.c_str());
CCLOG("At start of Clone, attachment is %s", attDone->name);
}
// add the attachment to the skin under the slot index and name
Skin_addAttachment(skin, slotIndex, slotName.c_str(), SUPER_CAST(spAttachment, result));
// tell the current spine::SkeletonAnimation to use the newest attachment
bool set = mSpine->setAttachment(slotName.c_str(), newRegion.c_str());
// testing a specific slot
---
this is the slot name "Torso" at this point, the attachment name is "merchant_torso"
if(slotIndex == 3) {
spAttachment* attDone = spSkin_getAttachment(skin, slotIndex, slotName.c_str());
CCLOG("At end of Clone, attachment is %s", attDone->name);
}
}
break;
}
}
}
The log output for the Torso slot is:
At start of Clone, attachment is crew_torso
At end of Clone, attachment is merchant_torso
So, as far as I can tell, I have successfully added the attachment and even set it for that skin. However, the Spine is not visually different.
Any help is highly appreciated, I've been banging my head against this for days now.