Hmm, I just stumbled into another issue with this: I can only replace items through a skin, not add them.
The setup I'm trying now is that my character has no parts in the "default" skin. The full character is in the "normal" skin and certain parts are replaced by specific skins that I add to it with the code from my starting post. This works fine if the specific skins overwrite elements, but doesn't work if the elements don't exist in the "normal" skin. So for example, if the "normal" skin has hair, then the "mohawk" skin can replace that hair with something different. But if the "normal" skin doesn't have a sword, then I can't add a sword in a skin. This seems odd to me, since looking at the code for spSkin_addAttachment it doesn't seem to check for anything, it just adds stuff and I indeed see the entries in the debugger, but they don't appear in-game.
To give an example, on the below JSON skin descriptions the "Mohawk" skin works but "BroadSword" does not. (Note that I've removed most other elements to keep the example short.)
"bones": [
{ "name": "root" },
{ "name": "Pelvis", "parent": "root", "x": 9.6, "y": 206.69, "color": "80ff00ff" },
{ "name": "Head", "parent": "Chest", "length": 59.21, "rotation": -2.54, "x": 132.88 },
{ "name": "Hair_Back", "parent": "Hair", "length": 130.25, "rotation": 163.97, "x": 7.08, "y": 19.29 },
{ "name": "LWeapon", "parent": "LWrist", "length": 291.39, "rotation": 82.91, "x": 28.52, "y": -23.43 }
],
"slots": [
{ "name": "Hair_Back", "bone": "Hair_Back", "attachment": "Hair_Back" },
{ "name": "LWeapon", "bone": "LWeapon", "attachment": "LWeapon" },
{ "name": "Head", "bone": "Head", "attachment": "Head" }
],
"skins": {
"default": {},
"BroadSword": {
"LWeapon": {
"LWeapon": { "name": "broadsword", "x": 182.54, "y": 7.29, "rotation": 3.02, "width": 405, "height": 77 }
}
},
"Mohawk": {
"Hair_Back": {
"Hair_Back": { "name": "hair_b", "x": 15.38, "y": 1.24, "rotation": 109.3, "width": 131, "height": 177 }
}
},
"Normal": {
"Hair_Back": {
"Hair_Back": { "name": "hair_a_back", "x": 69.25, "y": -10.54, "rotation": 109.3, "width": 111, "height": 162 }
},
"Head": {
"Head": { "name": "Head_neut", "x": 26.33, "y": 3.28, "rotation": -86.73, "width": 68, "height": 71 }
},
},
},
How should I code this to make it work?
By the way, an ugly workaround we found is that if we add a weapon texture that is just one empty pixel to the "Normal" skin then it works: since it's transparent it's not visible and the "BroadSword" skin can replace that texture. I do feel a bit dirty now so I'd still like to know what the proper way is to achieve this. 🙂