[cocos2d-x] Spine 组件所有特性原生平台适配

This commit is contained in:
SmallMain
2022-07-05 11:05:41 +08:00
parent f4599764fe
commit 3b1584ee1c
25 changed files with 1801 additions and 312 deletions

View File

@@ -60,9 +60,12 @@ RegionAttachment *AtlasAttachmentLoader::newRegionAttachment(Skin &skin, const S
RegionAttachment &attachment = *attachmentP;
attachment.setRendererObject(regionP);
attachment.setUVs(region.u, region.v, region.u2, region.v2, region.rotate);
attachment.setUVs(region.u, region.v, region.u2, region.v2, region.degrees);
attachment._regionDegrees = region.degrees;
attachment._regionOffsetX = region.offsetX;
attachment._regionOffsetY = region.offsetY;
attachment._regionX = region.x;
attachment._regionY = region.y;
attachment._regionWidth = (float)region.width;
attachment._regionHeight = (float)region.height;
attachment._regionOriginalWidth = (float)region.originalWidth;
@@ -90,6 +93,8 @@ MeshAttachment *AtlasAttachmentLoader::newMeshAttachment(Skin &skin, const Strin
attachment._regionDegrees = region.degrees;
attachment._regionOffsetX = region.offsetX;
attachment._regionOffsetY = region.offsetY;
attachment._regionX = region.x;
attachment._regionY = region.y;
attachment._regionWidth = (float)region.width;
attachment._regionHeight = (float)region.height;
attachment._regionOriginalWidth = (float)region.originalWidth;

View File

@@ -98,8 +98,8 @@ void MeshAttachment::updateUVs() {
return;
}
case 270: {
float textureWidth = _regionWidth / (_regionU2 - _regionU);
float textureHeight = _regionHeight / (_regionV2 - _regionV);
float textureWidth = _regionHeight / (_regionV2 - _regionV);
float textureHeight = _regionWidth / (_regionU2 - _regionU);
u -= _regionOffsetY / textureWidth;
v -= _regionOffsetX / textureHeight;
width = _regionOriginalHeight / textureWidth;
@@ -217,6 +217,22 @@ void MeshAttachment::setRegionOffsetY(float inValue) {
_regionOffsetY = inValue;
}
float MeshAttachment::getRegionX() {
return _regionX;
}
void MeshAttachment::setRegionX(float inValue) {
_regionX = inValue;
}
float MeshAttachment::getRegionY() {
return _regionY;
}
void MeshAttachment::setRegionY(float inValue) {
_regionY = inValue;
}
float MeshAttachment::getRegionWidth() {
return _regionWidth;
}

View File

@@ -91,6 +91,12 @@ namespace spine {
float getRegionOffsetY();
void setRegionOffsetY(float inValue);
float getRegionX();
void setRegionX(float inValue);
float getRegionY();
void setRegionY(float inValue);
float getRegionWidth();
void setRegionWidth(float inValue);
@@ -120,7 +126,7 @@ namespace spine {
MeshAttachment* newLinkedMesh();
private:
float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight;
float _regionOffsetX, _regionOffsetY, _regionX, _regionY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight;
MeshAttachment* _parentMesh;
Vector<float> _uvs;
Vector<float> _regionUVs;

View File

@@ -103,26 +103,35 @@ void RegionAttachment::updateOffset() {
_vertexOffset[BRY] = localYCos + localX2Sin;
}
void RegionAttachment::setUVs(float u, float v, float u2, float v2, bool rotate) {
if (rotate) {
_uvs[URX] = u;
_uvs[URY] = v2;
_uvs[BRX] = u;
_uvs[BRY] = v;
_uvs[BLX] = u2;
_uvs[BLY] = v;
_uvs[ULX] = u2;
_uvs[ULY] = v2;
} else {
_uvs[ULX] = u;
_uvs[ULY] = v2;
_uvs[URX] = u;
_uvs[URY] = v;
_uvs[BRX] = u2;
_uvs[BRY] = v;
_uvs[BLX] = u2;
_uvs[BLY] = v2;
}
void RegionAttachment::setUVs(float u, float v, float u2, float v2, float degrees) {
if (degrees == 90) {
_uvs[URX] = u;
_uvs[URY] = v2;
_uvs[BRX] = u;
_uvs[BRY] = v;
_uvs[BLX] = u2;
_uvs[BLY] = v;
_uvs[ULX] = u2;
_uvs[ULY] = v2;
} else if (degrees == 270) {
_uvs[BLX] = u;
_uvs[BLY] = v2;
_uvs[ULX] = u;
_uvs[ULY] = v;
_uvs[URX] = u2;
_uvs[URY] = v;
_uvs[BRX] = u2;
_uvs[BRY] = v2;
} else {
_uvs[ULX] = u;
_uvs[ULY] = v2;
_uvs[URX] = u;
_uvs[URY] = v;
_uvs[BRX] = u2;
_uvs[BRY] = v;
_uvs[BLX] = u2;
_uvs[BLY] = v2;
}
}
void RegionAttachment::computeWorldVertices(Bone &bone, Vector<float> &worldVertices, size_t offset, size_t stride) {
@@ -223,6 +232,14 @@ void RegionAttachment::setPath(const String &inValue) {
_path = inValue;
}
float RegionAttachment::getRegionDegrees() {
return _regionDegrees;
}
void RegionAttachment::setRegionDegrees(float inValue) {
_regionDegrees = inValue;
}
float RegionAttachment::getRegionOffsetX() {
return _regionOffsetX;
}
@@ -239,6 +256,22 @@ void RegionAttachment::setRegionOffsetY(float inValue) {
_regionOffsetY = inValue;
}
float RegionAttachment::getRegionX() {
return _regionX;
}
void RegionAttachment::setRegionX(float inValue) {
_regionX = inValue;
}
float RegionAttachment::getRegionY() {
return _regionY;
}
void RegionAttachment::setRegionY(float inValue) {
_regionY = inValue;
}
float RegionAttachment::getRegionWidth() {
return _regionWidth;
}

View File

@@ -54,7 +54,7 @@ namespace spine {
void updateOffset();
void setUVs(float u, float v, float u2, float v2, bool rotate);
void setUVs(float u, float v, float u2, float v2, float degress);
/// Transforms the attachment's four vertices to world coordinates.
/// @param bone The parent bone.
@@ -84,12 +84,21 @@ namespace spine {
const String& getPath();
void setPath(const String& inValue);
float getRegionDegrees();
void setRegionDegrees(float inValue);
float getRegionOffsetX();
void setRegionOffsetX(float inValue);
float getRegionOffsetY();
void setRegionOffsetY(float inValue);
float getRegionX();
void setRegionX(float inValue);
float getRegionY();
void setRegionY(float inValue);
float getRegionWidth();
void setRegionWidth(float inValue);
@@ -118,7 +127,7 @@ namespace spine {
static const int BRY;
float _x, _y, _rotation, _scaleX, _scaleY, _width, _height;
float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight;
float _regionOffsetX, _regionOffsetY, _regionX, _regionY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight;
Vector<float> _vertexOffset;
Vector<float> _uvs;
String _path;
@@ -127,6 +136,7 @@ namespace spine {
float _regionU2;
float _regionV2;
Color _color;
float _regionDegrees;
};
}

View File

@@ -143,6 +143,29 @@ Skin::AttachmentMap::Entries Skin::getAttachments() {
return _attachments.getEntries();
}
std::vector<std::map<std::string, Attachment *>> Skin::getAttachmentsForJSB() {
std::vector<std::map<std::string, Attachment *>> vec;
Skin::AttachmentMap::Entries entries = _attachments.getEntries();
size_t slotIndex = -1;
std::map<std::string, Attachment *>* map = nullptr;
while (entries.hasNext()) {
Skin::AttachmentMap::Entry &entry = entries.next();
if (slotIndex != entry._slotIndex){
slotIndex = entry._slotIndex;
vec.emplace_back();
map = &vec.back();
}
map->insert({ entry._name.buffer(), entry._attachment });
}
return vec;
}
void Skin::attachAll(Skeleton &skeleton, Skin &oldSkin) {
Vector<Slot *> &slots = skeleton.getSlots();
Skin::AttachmentMap::Entries entries = oldSkin.getAttachments();

View File

@@ -147,6 +147,8 @@ public:
AttachmentMap::Entries getAttachments();
std::vector<std::map<std::string, Attachment *>> getAttachmentsForJSB();
Vector<BoneData*>& getBones();
Vector<ConstraintData*>& getConstraints();