Stephen Gowen 7 ani în urmă
părinte
comite
e91a12cff1

+ 1 - 0
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);

+ 19 - 15
spine-cpp/spine-cpp/include/spine/MeshAttachment.h

@@ -33,6 +33,8 @@
 
 #include <spine/VertexAttachment.h>
 
+#include <spine/Vector.h>
+
 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<float>& RegionUVs { get { return _regionUVs; } set { _regionUVs = value; } }
 //        /// The UV pair for each vertex, normalized within the entire texture. <seealso cref="MeshAttachment.updateUVs"/>
-//        float[] UVs { get { return _uvs; } set { _uvs = value; } }
-//        int[] Triangles { get { return _triangles; } set { _triangles = value; } }
+//        Vector<float>& UVs { get { return _uvs; } set { _uvs = value; } }
+//        Vector<int>& 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<int>& 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<float> _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<float> _uvs;
+        Vector<float> _regionUVs;
+        Vector<int> _triangles;
+        Vector<int> _edges;
         float _r = 1, _g = 1, _b = 1, _a = 1;
         int _hulllength;
         bool _inheritDeform;

+ 34 - 62
spine-cpp/spine-cpp/include/spine/RegionAttachment.h

@@ -38,6 +38,8 @@
 
 #include <assert.h>
 
+#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<float>& Offset { get { return _offset; } }
+//        Vector<float>& 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<float> 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<float>& 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<float> _offset;
+        Vector<float> _uvs;
+        float r = 1, g = 1, b = 1, a = 1;
     };
 }
 

+ 43 - 0
spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp

@@ -30,7 +30,50 @@
 
 #include <spine/RegionAttachment.h>
 
+#include <spine/Bone.h>
+
 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);
 }

+ 2 - 2
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)