This commit is contained in:
Stephen Gowen 2017-11-09 11:04:29 -05:00
parent c20f4a5c79
commit e91a12cff1
5 changed files with 99 additions and 79 deletions

View File

@ -55,6 +55,7 @@ namespace Spine
friend class VertexAttachment; friend class VertexAttachment;
friend class PathConstraint; friend class PathConstraint;
friend class Skeleton; friend class Skeleton;
friend class RegionAttachment;
public: public:
static void setYDown(bool inValue); static void setYDown(bool inValue);

View File

@ -33,6 +33,8 @@
#include <spine/VertexAttachment.h> #include <spine/VertexAttachment.h>
#include <spine/Vector.h>
namespace Spine namespace Spine
{ {
/// Attachment that displays a texture region using a mesh. /// Attachment that displays a texture region using a mesh.
@ -42,18 +44,18 @@ namespace Spine
public: public:
// int HullLength { get { return _hulllength; } set { _hulllength = value; } } // int HullLength { get { return _hulllength; } set { _hulllength = value; } }
// float[] RegionUVs { get { return _regionUVs; } set { _regionUVs = value; } } // Vector<float>& RegionUVs { get { return _regionUVs; } set { _regionUVs = value; } }
// /// The UV pair for each vertex, normalized within the entire texture. <seealso cref="MeshAttachment.updateUVs"/> // /// The UV pair for each vertex, normalized within the entire texture. <seealso cref="MeshAttachment.updateUVs"/>
// float[] UVs { get { return _uvs; } set { _uvs = value; } } // Vector<float>& UVs { get { return _uvs; } set { _uvs = value; } }
// int[] Triangles { get { return _triangles; } set { _triangles = value; } } // Vector<int>& Triangles { get { return _triangles; } set { _triangles = value; } }
// //
// float R { get { return r; } set { r = value; } } // float R { get { return r; } set { r = value; } }
// float G { get { return g; } set { g = value; } } // float G { get { return g; } set { g = value; } }
// float B { get { return b; } set { b = value; } } // float B { get { return b; } set { b = value; } }
// float A { get { return a; } set { a = value; } } // float A { get { return a; } set { a = value; } }
// //
// string Path { get; set; } // std::string Path { get; set; }
// object RendererObject; //Object RendererObject { get; set; } // void* RendererObject; //Object RendererObject { get; set; }
// float RegionU { get; set; } // float RegionU { get; set; }
// float RegionV { get; set; } // float RegionV { get; set; }
// float RegionU2 { get; set; } // float RegionU2 { get; set; }
@ -87,15 +89,15 @@ namespace Spine
// } // }
// //
// // Nonessential. // // Nonessential.
// int[] Edges { get; set; } // Vector<int>& Edges { get; set; }
// float Width { get; set; } // float Width { get; set; }
// float Height { get; set; } // float Height { get; set; }
//
// MeshAttachment (string name) : VertexAttachment(name) MeshAttachment(std::string name) : VertexAttachment(name)
// { {
// // Empty // Empty
// } }
//
// void updateUVs() // void updateUVs()
// { // {
// float u = RegionU, v = RegionV, width = RegionU2 - RegionU, height = RegionV2 - RegionV; // float u = RegionU, v = RegionV, width = RegionU2 - RegionU, height = RegionV2 - RegionV;
@ -104,7 +106,7 @@ namespace Spine
// _uvs = new float[_regionUVs.Length]; // _uvs = new float[_regionUVs.Length];
// } // }
// //
// float[] _uvs = _uvs; // Vector<float> _uvs = _uvs;
// if (_regionRotate) // if (_regionRotate)
// { // {
// for (int i = 0, n = _uvs.Length; i < n; i += 2) // for (int i = 0, n = _uvs.Length; i < n; i += 2)
@ -131,8 +133,10 @@ namespace Spine
private: private:
float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight; float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight;
MeshAttachment* _parentMesh; MeshAttachment* _parentMesh;
// float[] _uvs, _regionUVs; Vector<float> _uvs;
// int[] _triangles; Vector<float> _regionUVs;
Vector<int> _triangles;
Vector<int> _edges;
float _r = 1, _g = 1, _b = 1, _a = 1; float _r = 1, _g = 1, _b = 1, _a = 1;
int _hulllength; int _hulllength;
bool _inheritDeform; bool _inheritDeform;

View File

@ -38,6 +38,8 @@
#include <assert.h> #include <assert.h>
#define NUM_UVS 8
namespace Spine namespace Spine
{ {
class Bone; class Bone;
@ -47,16 +49,7 @@ namespace Spine
{ {
RTTI_DECL; RTTI_DECL;
// public: 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;
//
// float X { get { return x; } set { x = value; } } // float X { get { return x; } set { x = value; } }
// float Y { get { return y; } set { y = value; } } // float Y { get { return y; } set { y = value; } }
// float Rotation { get { return _rotation; } set { _rotation = value; } } // float Rotation { get { return _rotation; } set { _rotation = value; } }
@ -71,7 +64,7 @@ namespace Spine
// float A { get { return a; } set { a = value; } } // float A { get { return a; } set { a = value; } }
// //
// std::string Path { get; set; } // 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 RegionOffsetX { get { return _regionOffsetX; } set { _regionOffsetX = value; } }
// float RegionOffsetY { get { return _regionOffsetY; } set { _regionOffsetY = value; } } // Pixels stripped from the bottom left, unrotated. // float RegionOffsetY { get { return _regionOffsetY; } set { _regionOffsetY = value; } } // Pixels stripped from the bottom left, unrotated.
// float RegionWidth { get { return _regionWidth; } set { _regionWidth = value; } } // float RegionWidth { get { return _regionWidth; } set { _regionWidth = value; } }
@ -79,14 +72,15 @@ namespace Spine
// float RegionOriginalWidth { get { return _regionOriginalWidth; } set { _regionOriginalWidth = value; } } // float RegionOriginalWidth { get { return _regionOriginalWidth; } set { _regionOriginalWidth = value; } }
// float RegionOriginalHeight { get { return _regionOriginalHeight; } set { _regionOriginalHeight = value; } } // Unrotated, unstripped size. // float RegionOriginalHeight { get { return _regionOriginalHeight; } set { _regionOriginalHeight = value; } } // Unrotated, unstripped size.
// //
// float[] Offset { get { return _offset; } } // Vector<float>& Offset { get { return _offset; } }
// float[] UVs { get { return _uvs; } } // Vector<float>& UVs { get { return _uvs; } }
//
// RegionAttachment (std::string name) : Attachment(name)
// {
// // Empty
// }
// //
RegionAttachment(std::string name) : Attachment(name)
{
_offset.reserve(NUM_UVS);
_uvs.reserve(NUM_UVS);
}
//
// void updateOffset() // void updateOffset()
// { // {
// float regionScaleX = _width / _regionOriginalWidth * _scaleX; // float regionScaleX = _width / _regionOriginalWidth * _scaleX;
@ -142,50 +136,28 @@ namespace Spine
// } // }
// } // }
// //
// /// Transforms the attachment's four vertices to world coordinates. /// Transforms the attachment's four vertices to world coordinates.
// /// @param bone The parent bone. /// @param bone The parent bone.
// /// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + 8. /// @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 offset The worldVertices index to begin writing values.
// /// @param stride The number of worldVertices entries between the value pairs written. /// @param stride The number of worldVertices entries between the value pairs written.
// void computeWorldVertices(Bone& bone, Vector<float> worldVertices, int offset, int stride = 2) void computeWorldVertices(Bone& bone, Vector<float>& worldVertices, int offset, int stride = 2);
// {
// assert(worldVertices.size() >= 8); private:
// static const int BLX;
// float[] vertexOffset = _offset; static const int BLY;
// float bwx = bone.worldX, bwy = bone.worldY; static const int ULX;
// float a = bone.a, b = bone.b, c = bone.c, d = bone.d; static const int ULY;
// float offsetX, offsetY; static const int URX;
// static const int URY;
// offsetX = vertexOffset[BRX]; // 0 static const int BRX;
// offsetY = vertexOffset[BRY]; // 1 static const int BRY;
// worldVertices[offset] = offsetX * a + offsetY * b + bwx; // bl
// worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy; float _x, _y, _rotation, _scaleX = 1, _scaleY = 1, _width, _height;
// offset += stride; float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight;
// Vector<float> _offset;
// offsetX = vertexOffset[BLX]; // 2 Vector<float> _uvs;
// offsetY = vertexOffset[BLY]; // 3 float r = 1, g = 1, b = 1, a = 1;
// 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;
}; };
} }

View File

@ -30,7 +30,50 @@
#include <spine/RegionAttachment.h> #include <spine/RegionAttachment.h>
#include <spine/Bone.h>
namespace Spine 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<float>& 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); RTTI_IMPL(RegionAttachment, Attachment);
} }

View File

@ -480,7 +480,7 @@ namespace Spine
{ {
outVertexBuffer.reserve(8); outVertexBuffer.reserve(8);
} }
// regionAttachment->computeWorldVertices(slot->getBone(), outVertexBuffer, 0); regionAttachment->computeWorldVertices(slot->getBone(), outVertexBuffer, 0);
} }
else if (attachment != NULL && attachment->getRTTI().derivesFrom(MeshAttachment::rtti)) else if (attachment != NULL && attachment->getRTTI().derivesFrom(MeshAttachment::rtti))
{ {
@ -492,7 +492,7 @@ namespace Spine
outVertexBuffer.reserve(verticesLength); 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) for (int ii = 0; ii < verticesLength; ii += 2)