三国卡牌客户端基础资源仓库
hch
6 天以前 e35c8e096041b3cf97d91677bf8d6c4587223a9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/******************************************************************************
 * Spine Runtimes License Agreement
 * Last updated July 28, 2023. Replaces all prior versions.
 *
 * Copyright (c) 2013-2023, Esoteric Software LLC
 *
 * Integration of the Spine Runtimes into software or otherwise creating
 * derivative works of the Spine Runtimes is permitted under the terms and
 * conditions of Section 2 of the Spine Editor License Agreement:
 * http://esotericsoftware.com/spine-editor-license
 *
 * Otherwise, it is permitted to integrate the Spine Runtimes into software or
 * otherwise create derivative works of the Spine Runtimes (collectively,
 * "Products"), provided that each user of the Products must obtain their own
 * Spine Editor license and redistribution of the Products in any form must
 * include this license and copyright notice.
 *
 * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
 * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
 * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *****************************************************************************/
 
using System;
 
namespace Spine {
    /// <summary>Attachment that displays a texture region using a mesh.</summary>
    public class MeshAttachment : VertexAttachment, IHasTextureRegion {
        internal TextureRegion region;
        internal string path;
        internal float[] regionUVs, uvs;
        internal int[] triangles;
        internal float r = 1, g = 1, b = 1, a = 1;
        internal int hullLength;
        private MeshAttachment parentMesh;
        private Sequence sequence;
 
        public TextureRegion Region {
            get { return region; }
            set {
                if (value == null) throw new ArgumentNullException("region", "region cannot be null.");
                region = value;
            }
        }
        public int HullLength { get { return hullLength; } set { hullLength = value; } }
        public float[] RegionUVs { get { return regionUVs; } set { regionUVs = value; } }
        /// <summary>The UV pair for each vertex, normalized within the entire texture.
        /// <seealso cref="MeshAttachment.UpdateRegion"/></summary>
        public float[] UVs { get { return uvs; } set { uvs = value; } }
        public int[] Triangles { get { return triangles; } set { triangles = value; } }
 
        public float R { get { return r; } set { r = value; } }
        public float G { get { return g; } set { g = value; } }
        public float B { get { return b; } set { b = value; } }
        public float A { get { return a; } set { a = value; } }
 
        public string Path { get { return path; } set { path = value; } }
        public Sequence Sequence { get { return sequence; } set { sequence = value; } }
 
        public MeshAttachment ParentMesh {
            get { return parentMesh; }
            set {
                parentMesh = value;
                if (value != null) {
                    bones = value.bones;
                    vertices = value.vertices;
                    worldVerticesLength = value.worldVerticesLength;
                    regionUVs = value.regionUVs;
                    triangles = value.triangles;
                    HullLength = value.HullLength;
                    Edges = value.Edges;
                    Width = value.Width;
                    Height = value.Height;
                }
            }
        }
 
        // Nonessential.
        public int[] Edges { get; set; }
        public float Width { get; set; }
        public float Height { get; set; }
 
        public MeshAttachment (string name)
            : base(name) {
        }
 
        /// <summary>Copy constructor. Use <see cref="NewLinkedMesh"/> if the other mesh is a linked mesh.</summary>
        protected MeshAttachment (MeshAttachment other)
            : base(other) {
 
            if (parentMesh != null) throw new ArgumentException("Use newLinkedMesh to copy a linked mesh.");
 
            region = other.region;
            path = other.path;
            r = other.r;
            g = other.g;
            b = other.b;
            a = other.a;
 
            regionUVs = new float[other.regionUVs.Length];
            Array.Copy(other.regionUVs, 0, regionUVs, 0, regionUVs.Length);
 
            uvs = new float[other.uvs.Length];
            Array.Copy(other.uvs, 0, uvs, 0, uvs.Length);
 
            triangles = new int[other.triangles.Length];
            Array.Copy(other.triangles, 0, triangles, 0, triangles.Length);
 
            hullLength = other.hullLength;
            sequence = other.sequence == null ? null : new Sequence(other.sequence);
 
            // Nonessential.
            if (other.Edges != null) {
                Edges = new int[other.Edges.Length];
                Array.Copy(other.Edges, 0, Edges, 0, Edges.Length);
            }
            Width = other.Width;
            Height = other.Height;
        }
 
 
        public void UpdateRegion () {
            float[] regionUVs = this.regionUVs;
            if (this.uvs == null || this.uvs.Length != regionUVs.Length) this.uvs = new float[regionUVs.Length];
            float[] uvs = this.uvs;
            int n = uvs.Length;
            float u, v, width, height;
 
            if (region is AtlasRegion) {
                u = this.region.u;
                v = this.region.v;
                AtlasRegion region = (AtlasRegion)this.region;
                // Note: difference from reference implementation.
                // Covers rotation since region.width and height are already setup accordingly.
                float textureWidth = this.region.width / (region.u2 - region.u);
                float textureHeight = this.region.height / (region.v2 - region.v);
                switch (region.degrees) {
                case 90:
                    u -= (region.originalHeight - region.offsetY - region.packedWidth) / textureWidth;
                    v -= (region.originalWidth - region.offsetX - region.packedHeight) / textureHeight;
                    width = region.originalHeight / textureWidth;
                    height = region.originalWidth / textureHeight;
                    for (int i = 0; i < n; i += 2) {
                        uvs[i] = u + regionUVs[i + 1] * width;
                        uvs[i + 1] = v + (1 - regionUVs[i]) * height;
                    }
                    return;
                case 180:
                    u -= (region.originalWidth - region.offsetX - region.packedWidth) / textureWidth;
                    v -= region.offsetY / textureHeight;
                    width = region.originalWidth / textureWidth;
                    height = region.originalHeight / textureHeight;
                    for (int i = 0; i < n; i += 2) {
                        uvs[i] = u + (1 - regionUVs[i]) * width;
                        uvs[i + 1] = v + (1 - regionUVs[i + 1]) * height;
                    }
                    return;
                case 270:
                    u -= region.offsetY / textureWidth;
                    v -= region.offsetX / textureHeight;
                    width = region.originalHeight / textureWidth;
                    height = region.originalWidth / textureHeight;
                    for (int i = 0; i < n; i += 2) {
                        uvs[i] = u + (1 - regionUVs[i + 1]) * width;
                        uvs[i + 1] = v + regionUVs[i] * height;
                    }
                    return;
                }
                u -= region.offsetX / textureWidth;
                v -= (region.originalHeight - region.offsetY - region.packedHeight) / textureHeight;
                width = region.originalWidth / textureWidth;
                height = region.originalHeight / textureHeight;
            } else if (region == null) {
                u = v = 0;
                width = height = 1;
            } else {
                u = region.u;
                v = region.v;
                width = region.u2 - u;
                height = region.v2 - v;
            }
            for (int i = 0; i < n; i += 2) {
                uvs[i] = u + regionUVs[i] * width;
                uvs[i + 1] = v + regionUVs[i + 1] * height;
            }
        }
 
        /// <summary>If the attachment has a <see cref="Sequence"/>, the region may be changed.</summary>
        override public void ComputeWorldVertices (Slot slot, int start, int count, float[] worldVertices, int offset, int stride = 2) {
            if (sequence != null) sequence.Apply(slot, this);
            base.ComputeWorldVertices(slot, start, count, worldVertices, offset, stride);
        }
 
        /// <summary>Returns a new mesh with this mesh set as the <see cref="ParentMesh"/>.
        public MeshAttachment NewLinkedMesh () {
            MeshAttachment mesh = new MeshAttachment(Name);
 
            mesh.timelineAttachment = timelineAttachment;
            mesh.region = region;
            mesh.path = path;
            mesh.r = r;
            mesh.g = g;
            mesh.b = b;
            mesh.a = a;
            mesh.ParentMesh = parentMesh != null ? parentMesh : this;
            if (mesh.Region != null) mesh.UpdateRegion();
            return mesh;
        }
 
        public override Attachment Copy () {
            return parentMesh != null ? NewLinkedMesh() : new MeshAttachment(this);
        }
    }
}