|
@@ -2,107 +2,95 @@ package spine.attachments;
|
|
|
|
|
|
import openfl.Vector;
|
|
|
import spine.Color;
|
|
|
+import spine.atlas.TextureAtlasRegion;
|
|
|
|
|
|
-class MeshAttachment extends VertexAttachment {
|
|
|
- public var uvs:Vector<Float>;
|
|
|
- public var regionUVs:Vector<Float>;
|
|
|
- public var triangles:Vector<Int>;
|
|
|
+class MeshAttachment extends VertexAttachment implements HasTextureRegion {
|
|
|
+ public var region:TextureRegion;
|
|
|
+ public var path:String;
|
|
|
+ public var regionUVs = new Vector<Float>();
|
|
|
+ public var uvs = new Vector<Float>();
|
|
|
+ public var triangles = new Vector<Int>();
|
|
|
public var color:Color = new Color(1, 1, 1, 1);
|
|
|
+ public var width:Float = 0;
|
|
|
+ public var height:Float = 0;
|
|
|
public var hullLength:Int = 0;
|
|
|
+ public var edges = new Vector<Int>();
|
|
|
+ public var rendererObject:Dynamic;
|
|
|
+ public var sequence:Sequence;
|
|
|
|
|
|
private var _parentMesh:MeshAttachment;
|
|
|
|
|
|
- public var path:String;
|
|
|
- public var rendererObject:Dynamic;
|
|
|
- public var regionU:Float = 0;
|
|
|
- public var regionV:Float = 0;
|
|
|
- public var regionU2:Float = 0;
|
|
|
- public var regionV2:Float = 0;
|
|
|
- public var regionDegrees:Int = 0;
|
|
|
- public var regionOffsetX:Float = 0; // Pixels stripped from the bottom left, unrotated.
|
|
|
- public var regionOffsetY:Float = 0;
|
|
|
- public var regionWidth:Float = 0; // Unrotated, stripped size.
|
|
|
- public var regionHeight:Float = 0;
|
|
|
- public var regionOriginalWidth:Float = 0; // Unrotated, unstripped size.
|
|
|
- public var regionOriginalHeight:Float = 0;
|
|
|
- // Nonessential.
|
|
|
- public var edges:Vector<Int>;
|
|
|
- public var width:Float = 0;
|
|
|
- public var height:Float = 0;
|
|
|
-
|
|
|
- public function new(name:String) {
|
|
|
+ public function new(name:String, path:String) {
|
|
|
super(name);
|
|
|
+ this.path = path;
|
|
|
}
|
|
|
|
|
|
- public function updateUVs():Void {
|
|
|
- var i:Int = 0, n:Int = regionUVs.length;
|
|
|
- var u:Float = regionU, v:Float = regionV;
|
|
|
- var width:Float = 0, height:Float = 0;
|
|
|
- var textureWidth:Float, textureHeight:Float;
|
|
|
- if (uvs == null || uvs.length != n)
|
|
|
- uvs = new Vector<Float>(n, true);
|
|
|
-
|
|
|
- switch (regionDegrees) {
|
|
|
- case 90:
|
|
|
- {
|
|
|
- textureWidth = regionHeight / (regionU2 - regionU);
|
|
|
- textureHeight = regionWidth / (regionV2 - regionV);
|
|
|
- u -= (regionOriginalHeight - regionOffsetY - regionHeight) / textureWidth;
|
|
|
- v -= (regionOriginalWidth - regionOffsetX - regionWidth) / textureHeight;
|
|
|
- width = regionOriginalHeight / textureWidth;
|
|
|
- height = regionOriginalWidth / textureHeight;
|
|
|
- i = 0;
|
|
|
+ public function updateRegion():Void {
|
|
|
+ if (region == null) {
|
|
|
+ trace("Region not set.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var regionUVs = this.regionUVs;
|
|
|
+ if (uvs.length != regionUVs.length)
|
|
|
+ uvs = new Vector<Float>(regionUVs.length, true);
|
|
|
+ var n = uvs.length;
|
|
|
+ var u = region.u, v = region.v, width:Float = 0, height:Float = 0;
|
|
|
+ if (Std.isOfType(region, TextureAtlasRegion)) {
|
|
|
+ var atlasRegion:TextureAtlasRegion = cast(region, TextureAtlasRegion);
|
|
|
+ var textureWidth = atlasRegion.page.width,
|
|
|
+ textureHeight = atlasRegion.page.height;
|
|
|
+ switch (atlasRegion.degrees) {
|
|
|
+ case 90:
|
|
|
+ u -= (region.originalHeight - region.offsetY - region.height) / textureWidth;
|
|
|
+ v -= (region.originalWidth - region.offsetX - region.width) / textureHeight;
|
|
|
+ width = region.originalHeight / textureWidth;
|
|
|
+ height = region.originalWidth / textureHeight;
|
|
|
+ var i = 0;
|
|
|
while (i < n) {
|
|
|
uvs[i] = u + regionUVs[i + 1] * width;
|
|
|
uvs[i + 1] = v + (1 - regionUVs[i]) * height;
|
|
|
i += 2;
|
|
|
}
|
|
|
- }
|
|
|
- case 180:
|
|
|
- {
|
|
|
- textureWidth = regionWidth / (regionU2 - regionU);
|
|
|
- textureHeight = regionHeight / (regionV2 - regionV);
|
|
|
- u -= (regionOriginalWidth - regionOffsetX - regionWidth) / textureWidth;
|
|
|
- v -= regionOffsetY / textureHeight;
|
|
|
- width = regionOriginalWidth / textureWidth;
|
|
|
- height = regionOriginalHeight / textureHeight;
|
|
|
- i = 0;
|
|
|
+ return;
|
|
|
+ case 180:
|
|
|
+ u -= (region.originalWidth - region.offsetX - region.width) / textureWidth;
|
|
|
+ v -= region.offsetY / textureHeight;
|
|
|
+ width = region.originalWidth / textureWidth;
|
|
|
+ height = region.originalHeight / textureHeight;
|
|
|
+ var i = 0;
|
|
|
while (i < n) {
|
|
|
uvs[i] = u + (1 - regionUVs[i]) * width;
|
|
|
uvs[i + 1] = v + (1 - regionUVs[i + 1]) * height;
|
|
|
i += 2;
|
|
|
}
|
|
|
- }
|
|
|
- case 270:
|
|
|
- {
|
|
|
- textureWidth = regionWidth / (regionU2 - regionU);
|
|
|
- textureHeight = regionHeight / (regionV2 - regionV);
|
|
|
- u -= regionOffsetY / textureWidth;
|
|
|
- v -= regionOffsetX / textureHeight;
|
|
|
- width = regionOriginalHeight / textureWidth;
|
|
|
- height = regionOriginalWidth / textureHeight;
|
|
|
- i = 0;
|
|
|
+ return;
|
|
|
+ case 270:
|
|
|
+ u -= region.offsetY / textureWidth;
|
|
|
+ v -= region.offsetX / textureHeight;
|
|
|
+ width = region.originalHeight / textureWidth;
|
|
|
+ height = region.originalWidth / textureHeight;
|
|
|
+ var i = 0;
|
|
|
while (i < n) {
|
|
|
uvs[i] = u + (1 - regionUVs[i + 1]) * width;
|
|
|
uvs[i + 1] = v + regionUVs[i] * height;
|
|
|
- i += 2;
|
|
|
}
|
|
|
- }
|
|
|
- default:
|
|
|
- {
|
|
|
- textureWidth = regionWidth / (regionU2 - regionU);
|
|
|
- textureHeight = regionHeight / (regionV2 - regionV);
|
|
|
- u -= regionOffsetX / textureWidth;
|
|
|
- v -= (regionOriginalHeight - regionOffsetY - regionHeight) / textureHeight;
|
|
|
- width = regionOriginalWidth / textureWidth;
|
|
|
- height = regionOriginalHeight / textureHeight;
|
|
|
- i = 0;
|
|
|
- while (i < n) {
|
|
|
- uvs[i] = u + regionUVs[i] * width;
|
|
|
- uvs[i + 1] = v + regionUVs[i + 1] * height;
|
|
|
- i += 2;
|
|
|
- }
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ u -= region.offsetX / textureWidth;
|
|
|
+ v -= (region.originalHeight - region.offsetY - region.height) / textureHeight;
|
|
|
+ width = region.originalWidth / textureWidth;
|
|
|
+ height = region.originalHeight / textureHeight;
|
|
|
+ } else if (region == null) {
|
|
|
+ u = v = 0;
|
|
|
+ width = height = 1;
|
|
|
+ } else {
|
|
|
+ width = this.region.u2 - u;
|
|
|
+ height = this.region.v2 - v;
|
|
|
+ }
|
|
|
+ var i = 0;
|
|
|
+ while (i < n) {
|
|
|
+ uvs[i] = u + regionUVs[i] * width;
|
|
|
+ uvs[i + 1] = v + regionUVs[i + 1] * height;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -129,62 +117,46 @@ class MeshAttachment extends VertexAttachment {
|
|
|
}
|
|
|
|
|
|
override public function copy():Attachment {
|
|
|
- var copy:MeshAttachment = new MeshAttachment(name);
|
|
|
- copy.rendererObject = rendererObject;
|
|
|
- copy.regionU = regionU;
|
|
|
- copy.regionV = regionV;
|
|
|
- copy.regionU2 = regionU2;
|
|
|
- copy.regionV2 = regionV2;
|
|
|
- copy.regionDegrees = regionDegrees;
|
|
|
- copy.regionOffsetX = regionOffsetX;
|
|
|
- copy.regionOffsetY = regionOffsetY;
|
|
|
- copy.regionWidth = regionWidth;
|
|
|
- copy.regionHeight = regionHeight;
|
|
|
- copy.regionOriginalWidth = regionOriginalWidth;
|
|
|
- copy.regionOriginalHeight = regionOriginalHeight;
|
|
|
- copy.path = path;
|
|
|
+ if (parentMesh != null)
|
|
|
+ return newLinkedMesh();
|
|
|
+
|
|
|
+ var copy:MeshAttachment = new MeshAttachment(name, this.path);
|
|
|
+ copy.region = region;
|
|
|
copy.color.setFromColor(color);
|
|
|
+ copy.rendererObject = rendererObject;
|
|
|
|
|
|
- if (parentMesh == null) {
|
|
|
- this.copyTo(copy);
|
|
|
- copy.regionUVs = regionUVs.concat();
|
|
|
- copy.uvs = uvs.concat();
|
|
|
- copy.triangles = triangles.concat();
|
|
|
- copy.hullLength = hullLength;
|
|
|
+ this.copyTo(copy);
|
|
|
+ copy.regionUVs = regionUVs.concat();
|
|
|
+ copy.uvs = uvs.concat();
|
|
|
+ copy.triangles = triangles.concat();
|
|
|
+ copy.hullLength = hullLength;
|
|
|
|
|
|
- // Nonessential.
|
|
|
- if (edges != null) {
|
|
|
- copy.edges = edges.concat();
|
|
|
- }
|
|
|
- copy.width = width;
|
|
|
- copy.height = height;
|
|
|
- } else {
|
|
|
- copy.parentMesh = parentMesh;
|
|
|
- copy.updateUVs();
|
|
|
+ copy.sequence = sequence != null ? sequence.copy() : null;
|
|
|
+
|
|
|
+ if (edges != null) {
|
|
|
+ copy.edges = edges.concat();
|
|
|
}
|
|
|
+ copy.width = width;
|
|
|
+ copy.height = height;
|
|
|
|
|
|
return copy;
|
|
|
}
|
|
|
|
|
|
+ public override function computeWorldVertices(slot:Slot, start:Int, count:Int, worldVertices:Vector<Float>, offset:Int, stride:Int):Void {
|
|
|
+ if (sequence != null)
|
|
|
+ sequence.apply(slot, this);
|
|
|
+ super.computeWorldVertices(slot, start, count, worldVertices, offset, stride);
|
|
|
+ }
|
|
|
+
|
|
|
public function newLinkedMesh():MeshAttachment {
|
|
|
- var copy:MeshAttachment = new MeshAttachment(name);
|
|
|
+ var copy:MeshAttachment = new MeshAttachment(name, path);
|
|
|
copy.rendererObject = rendererObject;
|
|
|
- copy.regionU = regionU;
|
|
|
- copy.regionV = regionV;
|
|
|
- copy.regionU2 = regionU2;
|
|
|
- copy.regionV2 = regionV2;
|
|
|
- copy.regionDegrees = regionDegrees;
|
|
|
- copy.regionOffsetX = regionOffsetX;
|
|
|
- copy.regionOffsetY = regionOffsetY;
|
|
|
- copy.regionWidth = regionWidth;
|
|
|
- copy.regionHeight = regionHeight;
|
|
|
- copy.regionOriginalWidth = regionOriginalWidth;
|
|
|
- copy.regionOriginalHeight = regionOriginalHeight;
|
|
|
- copy.path = path;
|
|
|
+ copy.region = region;
|
|
|
copy.color.setFromColor(color);
|
|
|
- copy.deformAttachment = deformAttachment;
|
|
|
- copy.parentMesh = parentMesh != null ? parentMesh : this;
|
|
|
- copy.updateUVs();
|
|
|
+ copy.timelineAttachment = timelineAttachment;
|
|
|
+ copy.parentMesh = this.parentMesh != null ? this.parentMesh : this;
|
|
|
+ if (copy.region != null)
|
|
|
+ copy.updateRegion();
|
|
|
return copy;
|
|
|
}
|
|
|
}
|