diff --git a/spine-cpp/spine-cpp/include/spine/Bone.h b/spine-cpp/spine-cpp/include/spine/Bone.h index 5cf390cad..ac20652c0 100644 --- a/spine-cpp/spine-cpp/include/spine/Bone.h +++ b/spine-cpp/spine-cpp/include/spine/Bone.h @@ -55,6 +55,7 @@ namespace Spine friend class VertexAttachment; friend class PathConstraint; friend class Skeleton; + friend class RegionAttachment; public: static void setYDown(bool inValue); diff --git a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h index e6e1b7b48..fee9b9abf 100644 --- a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h @@ -33,6 +33,8 @@ #include +#include + namespace Spine { /// Attachment that displays a texture region using a mesh. @@ -42,18 +44,18 @@ namespace Spine public: // int HullLength { get { return _hulllength; } set { _hulllength = value; } } -// float[] RegionUVs { get { return _regionUVs; } set { _regionUVs = value; } } +// Vector& RegionUVs { get { return _regionUVs; } set { _regionUVs = value; } } // /// The UV pair for each vertex, normalized within the entire texture. -// float[] UVs { get { return _uvs; } set { _uvs = value; } } -// int[] Triangles { get { return _triangles; } set { _triangles = value; } } +// Vector& UVs { get { return _uvs; } set { _uvs = value; } } +// Vector& Triangles { get { return _triangles; } set { _triangles = value; } } // // float R { get { return r; } set { r = value; } } // float G { get { return g; } set { g = value; } } // float B { get { return b; } set { b = value; } } // float A { get { return a; } set { a = value; } } // -// string Path { get; set; } -// object RendererObject; //Object RendererObject { get; set; } +// std::string Path { get; set; } +// void* RendererObject; //Object RendererObject { get; set; } // float RegionU { get; set; } // float RegionV { get; set; } // float RegionU2 { get; set; } @@ -87,15 +89,15 @@ namespace Spine // } // // // Nonessential. -// int[] Edges { get; set; } +// Vector& Edges { get; set; } // float Width { get; set; } // float Height { get; set; } -// -// MeshAttachment (string name) : VertexAttachment(name) -// { -// // Empty -// } -// + + MeshAttachment(std::string name) : VertexAttachment(name) + { + // Empty + } + // void updateUVs() // { // float u = RegionU, v = RegionV, width = RegionU2 - RegionU, height = RegionV2 - RegionV; @@ -104,7 +106,7 @@ namespace Spine // _uvs = new float[_regionUVs.Length]; // } // -// float[] _uvs = _uvs; +// Vector _uvs = _uvs; // if (_regionRotate) // { // for (int i = 0, n = _uvs.Length; i < n; i += 2) @@ -131,8 +133,10 @@ namespace Spine private: float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight; MeshAttachment* _parentMesh; -// float[] _uvs, _regionUVs; -// int[] _triangles; + Vector _uvs; + Vector _regionUVs; + Vector _triangles; + Vector _edges; float _r = 1, _g = 1, _b = 1, _a = 1; int _hulllength; bool _inheritDeform; diff --git a/spine-cpp/spine-cpp/include/spine/RegionAttachment.h b/spine-cpp/spine-cpp/include/spine/RegionAttachment.h index 5a994730d..b8641b8f6 100644 --- a/spine-cpp/spine-cpp/include/spine/RegionAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/RegionAttachment.h @@ -38,6 +38,8 @@ #include +#define NUM_UVS 8 + namespace Spine { class Bone; @@ -47,16 +49,7 @@ namespace Spine { RTTI_DECL; -// public: -// const int BLX = 0; -// const int BLY = 1; -// const int ULX = 2; -// const int ULY = 3; -// const int URX = 4; -// const int URY = 5; -// const int BRX = 6; -// const int BRY = 7; -// + public: // float X { get { return x; } set { x = value; } } // float Y { get { return y; } set { y = value; } } // float Rotation { get { return _rotation; } set { _rotation = value; } } @@ -71,7 +64,7 @@ namespace Spine // float A { get { return a; } set { a = value; } } // // std::string Path { get; set; } -// object RendererObject; //object RendererObject { get; set; } +// void* RendererObject; //object RendererObject { get; set; } // float RegionOffsetX { get { return _regionOffsetX; } set { _regionOffsetX = value; } } // float RegionOffsetY { get { return _regionOffsetY; } set { _regionOffsetY = value; } } // Pixels stripped from the bottom left, unrotated. // float RegionWidth { get { return _regionWidth; } set { _regionWidth = value; } } @@ -79,14 +72,15 @@ namespace Spine // float RegionOriginalWidth { get { return _regionOriginalWidth; } set { _regionOriginalWidth = value; } } // float RegionOriginalHeight { get { return _regionOriginalHeight; } set { _regionOriginalHeight = value; } } // Unrotated, unstripped size. // -// float[] Offset { get { return _offset; } } -// float[] UVs { get { return _uvs; } } -// -// RegionAttachment (std::string name) : Attachment(name) -// { -// // Empty -// } +// Vector& Offset { get { return _offset; } } +// Vector& UVs { get { return _uvs; } } // + RegionAttachment(std::string name) : Attachment(name) + { + _offset.reserve(NUM_UVS); + _uvs.reserve(NUM_UVS); + } +// // void updateOffset() // { // float regionScaleX = _width / _regionOriginalWidth * _scaleX; @@ -142,50 +136,28 @@ namespace Spine // } // } // -// /// Transforms the attachment's four vertices to world coordinates. -// /// @param bone The parent bone. -// /// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + 8. -// /// @param offset The worldVertices index to begin writing values. -// /// @param stride The number of worldVertices entries between the value pairs written. -// void computeWorldVertices(Bone& bone, Vector worldVertices, int offset, int stride = 2) -// { -// assert(worldVertices.size() >= 8); -// -// float[] vertexOffset = _offset; -// float bwx = bone.worldX, bwy = bone.worldY; -// float a = bone.a, b = bone.b, c = bone.c, d = bone.d; -// float offsetX, offsetY; -// -// offsetX = vertexOffset[BRX]; // 0 -// offsetY = vertexOffset[BRY]; // 1 -// worldVertices[offset] = offsetX * a + offsetY * b + bwx; // bl -// worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy; -// offset += stride; -// -// offsetX = vertexOffset[BLX]; // 2 -// offsetY = vertexOffset[BLY]; // 3 -// worldVertices[offset] = offsetX * a + offsetY * b + bwx; // ul -// worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy; -// offset += stride; -// -// offsetX = vertexOffset[ULX]; // 4 -// offsetY = vertexOffset[ULY]; // 5 -// worldVertices[offset] = offsetX * a + offsetY * b + bwx; // ur -// worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy; -// offset += stride; -// -// offsetX = vertexOffset[URX]; // 6 -// offsetY = vertexOffset[URY]; // 7 -// worldVertices[offset] = offsetX * a + offsetY * b + bwx; // br -// worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy; -// } -// -// private: -// float _x, _y, _rotation, _scaleX = 1, _scaleY = 1, _width, _height; -// float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight; -// float[] _offset = new float[8]; -// float[] _uvs = new float[8]; -// float r = 1, g = 1, b = 1, a = 1; + /// Transforms the attachment's four vertices to world coordinates. + /// @param bone The parent bone. + /// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + 8. + /// @param offset The worldVertices index to begin writing values. + /// @param stride The number of worldVertices entries between the value pairs written. + void computeWorldVertices(Bone& bone, Vector& worldVertices, int offset, int stride = 2); + + private: + static const int BLX; + static const int BLY; + static const int ULX; + static const int ULY; + static const int URX; + static const int URY; + static const int BRX; + static const int BRY; + + float _x, _y, _rotation, _scaleX = 1, _scaleY = 1, _width, _height; + float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight; + Vector _offset; + Vector _uvs; + float r = 1, g = 1, b = 1, a = 1; }; } diff --git a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp index b5b78a49e..962999af9 100644 --- a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp @@ -30,7 +30,50 @@ #include +#include + namespace Spine { + const int RegionAttachment::BLX = 0; + const int RegionAttachment::BLY = 1; + const int RegionAttachment::ULX = 2; + const int RegionAttachment::ULY = 3; + const int RegionAttachment::URX = 4; + const int RegionAttachment::URY = 5; + const int RegionAttachment::BRX = 6; + const int RegionAttachment::BRY = 7; + + void RegionAttachment::computeWorldVertices(Bone& bone, Vector& worldVertices, int offset, int stride) + { + assert(worldVertices.size() >= (offset + 8)); + + float bwx = bone._worldX, bwy = bone._worldY; + float a = bone._a, b = bone._b, c = bone._c, d = bone._d; + float offsetX, offsetY; + + offsetX = _offset[BRX]; // 0 + offsetY = _offset[BRY]; // 1 + worldVertices[offset] = offsetX * a + offsetY * b + bwx; // bl + worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy; + offset += stride; + + offsetX = _offset[BLX]; // 2 + offsetY = _offset[BLY]; // 3 + worldVertices[offset] = offsetX * a + offsetY * b + bwx; // ul + worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy; + offset += stride; + + offsetX = _offset[ULX]; // 4 + offsetY = _offset[ULY]; // 5 + worldVertices[offset] = offsetX * a + offsetY * b + bwx; // ur + worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy; + offset += stride; + + offsetX = _offset[URX]; // 6 + offsetY = _offset[URY]; // 7 + worldVertices[offset] = offsetX * a + offsetY * b + bwx; // br + worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy; + } + RTTI_IMPL(RegionAttachment, Attachment); } diff --git a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp index f6e898b3b..783ddda3b 100644 --- a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp +++ b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp @@ -480,7 +480,7 @@ namespace Spine { outVertexBuffer.reserve(8); } -// regionAttachment->computeWorldVertices(slot->getBone(), outVertexBuffer, 0); + regionAttachment->computeWorldVertices(slot->getBone(), outVertexBuffer, 0); } else if (attachment != NULL && attachment->getRTTI().derivesFrom(MeshAttachment::rtti)) { @@ -492,7 +492,7 @@ namespace Spine outVertexBuffer.reserve(verticesLength); } -// mesh->computeWorldVertices(slot, 0, verticesLength, outVertexBuffer, 0); + mesh->computeWorldVertices(*slot, 0, verticesLength, outVertexBuffer, 0); } for (int ii = 0; ii < verticesLength; ii += 2)