From 0312d2725dc31220fcdf6f2273012154089d0ffa Mon Sep 17 00:00:00 2001 From: badlogic Date: Sat, 22 Dec 2018 15:07:26 +0100 Subject: [PATCH] [lua] Port of mesh whitespaces stripping. See #1232. --- spine-lua/attachments/MeshAttachment.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/spine-lua/attachments/MeshAttachment.lua b/spine-lua/attachments/MeshAttachment.lua index 400aa665e..c260c5fec 100644 --- a/spine-lua/attachments/MeshAttachment.lua +++ b/spine-lua/attachments/MeshAttachment.lua @@ -67,14 +67,26 @@ function MeshAttachment:updateUVs () width = 1 height = 1 else - u = self.region.u; - v = self.region.v; - width = self.region.u2 - u; - height = self.region.v2 - v; + local region = self.region + local textureWidth = region.page.width + local textureHeight = region.page.height + if region.rotate then + u = region.u - (region.originalHeight - region.offsetY - region.height) / textureWidth + v = region.v - (region.originalWidth - region.offsetX - region.width) / textureHeight + width = region.originalHeight / textureWidth + height = region.originalWidth / textureHeight + else + u = region.u - region.offsetX / textureWidth; + v = region.v - (region.originalHeight - region.offsetY - region.height) / textureHeight; + width = region.originalWidth / textureWidth; + height = region.originalHeight / textureHeight; + end end + local regionUVs = self.regionUVs if not self.uvs or (#self.uvs ~= #regionUVs) then self.uvs = utils.newNumberArray(#regionUVs) end local uvs = self.uvs + if self.region and self.region.rotate then local i = 0 local n = #uvs