int spSkeleton_setAttachment (spSkeleton* self, const char* slotName, const char* attachmentName) { int i; for (i = 0; i < self->slotCount; ++i) { spSlot *slot = self->slots[i]; if (strcmp(slot->data->name, slotName) == 0) { if (!attachmentName) spSlot_setAttachment(slot, 0); else { spAttachment* attachment = spSkeleton_getAttachmentForSlotIndex(self, i, attachmentName); if (!attachment) return 0; spSlot_setAttachment(slot, attachment); } return 1; } } return 0; }
void spSkin_attachAll (const spSkin* self, spSkeleton* skeleton, const spSkin* oldSkin) { const _Entry *entry = SUB_CAST(_spSkin, oldSkin)->entries; while (entry) { spSlot *slot = skeleton->slots[entry->slotIndex]; if (slot->attachment == entry->attachment) { spAttachment *attachment = spSkin_getAttachment(self, entry->slotIndex, entry->name); if (attachment) spSlot_setAttachment(slot, attachment); } entry = entry->next; } }
void spSkeleton_setSkin (spSkeleton* self, spSkin* newSkin) { if (!self->skin) { int i; for (i = 0; i < self->slotCount; ++i) { spSlot* slot = self->slots[i]; if (slot->data->attachmentName) { spAttachment* attachment = spSkin_getAttachment(newSkin, i, slot->data->attachmentName); if (attachment) spSlot_setAttachment(slot, attachment); } } } else if (newSkin) /**/ spSkin_attachAll(newSkin, self, self->skin); CONST_CAST(spSkin*, self->skin) = newSkin; }
void spSkeleton_setSkin (spSkeleton* self, spSkin* newSkin) { if (newSkin) { if (self->skin) spSkin_attachAll(newSkin, self, self->skin); else { /* No previous skin, attach setup pose attachments. */ int i; for (i = 0; i < self->slotsCount; ++i) { spSlot* slot = self->slots[i]; if (slot->data->attachmentName) { spAttachment* attachment = spSkin_getAttachment(newSkin, i, slot->data->attachmentName); if (attachment) spSlot_setAttachment(slot, attachment); } } } } CONST_CAST(spSkin*, self->skin) = newSkin; }
void spSlot_setToSetupPose (spSlot* self) { spAttachment* attachment = 0; self->r = self->data->r; self->g = self->data->g; self->b = self->data->b; self->a = self->data->a; if (self->data->attachmentName) { /* Find slot index. */ int i; for (i = 0; i < self->bone->skeleton->data->slotsCount; ++i) { if (self->data == self->bone->skeleton->data->slots[i]) { attachment = spSkeleton_getAttachmentForSlotIndex(self->bone->skeleton, i, self->data->attachmentName); break; } } } spSlot_setAttachment(self, attachment); }
bool SkeletonAnimation::replacementParts(const std::string& skinName, const std::string& attachmentName) { if (skinName.empty()) { return false; } spSkin *skin = spSkeletonData_findSkin(_skeleton->data, skinName.c_str()); if (!skin) return false; // if (_skeleton->skin) // { // const _Entry *entry = reinterpret_cast<_spSkin *>(_skeleton->skin)->entries; // while (entry) // { // spSlot *slot = _skeleton->slots[entry->slotIndex]; // if (strcmp(slot->data->name, attachmentName.c_str()) == 0) // { // spAttachment *attachment = spSkin_getAttachment(skin, entry->slotIndex, entry->name); // if (attachment) spSlot_setAttachment(slot, attachment); // return true; // } // entry = entry->next; // } // } // else // { for (int i = 0; i < _skeleton->slotsCount; ++i) { spSlot* slot = _skeleton->slots[i]; if (strcmp(slot->data->name, attachmentName.c_str()) == 0) { spAttachment* attachment = spSkin_getAttachment(skin, i, slot->data->attachmentName); if (attachment) spSlot_setAttachment(slot, attachment); return true; } } // } return false; }