I have a Spine character that I want to make customizable during runtime. For many of the customizations, I do not need to change the attachment in a slot, I only need to change the region (image from Atlas) to customize the character, for example hair, beard, armor tye, etc.
In the Spine editor I just change the region path under the slot's skin placeholder to create a bunch of different characters.
Is there a way to change the region for an attachment during runtime using spine-ts, I see in some of the Unity threads mentions of cloning attachments, I am wondering if that is the way or if there is something easier, if only the region/image needs to be changed.
Here's a first attempt, it kind of works, but feels pretty hacky (requires a skin reload to take effect and the hair is offset from the original location.)
I think the hardwiring of the uvs array to u,v,u2,v2 settings will also fail when the texture in the atlas is rotated.
I imagine there is a better 'clean' method to do this.
It's ok for the original skin to change, there is only one instantiation of the skeleton used (which might be something to revisit in the C3 plugin at some point.)
SetAttachment(slot, regionName){
const skeleton = this.skeletonInfo.skeleton;
const atlas = this.skeletonInfo.atlas;
let newRegion = atlas.findRegion(regionName)
console.log(newRegion)
let skin = skeleton.data.findSkin(this.skinName)
let slotIndex = skeleton.findSlot(slot).data.index
let regionAttachment = skin.getAttachment(slotIndex, 'hairs').copy();
console.log(regionAttachment)
regionAttachment.path = regionName
regionAttachment.name = regionName
regionAttachment.region = newRegion
regionAttachment.uvs[0] = regionAttachment.region.u2
regionAttachment.uvs[1] = regionAttachment.region.v2
regionAttachment.uvs[2] = regionAttachment.region.u
regionAttachment.uvs[3] = regionAttachment.region.v2
regionAttachment.uvs[4] = regionAttachment.region.u
regionAttachment.uvs[5] = regionAttachment.region.v
regionAttachment.uvs[6] = regionAttachment.region.u2
regionAttachment.uvs[7] = regionAttachment.region.v
console.log(regionAttachment)
console.log(skin)
skin.setAttachment(slotIndex, 'hairs', regionAttachment)
},