mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 18:26:12 +08:00
[lua] Ported rotated mesh region UV loading. See #1327.
This commit is contained in:
parent
cdd06b22f1
commit
5ad114f671
@ -186,7 +186,15 @@ function TextureAtlas:parse (atlasContent, imageLoader)
|
|||||||
region.name = line
|
region.name = line
|
||||||
region.page = page
|
region.page = page
|
||||||
|
|
||||||
if readValue() == "true" then region.rotate = true end
|
local rotateValue = readValue()
|
||||||
|
if rotateValue == "true" then
|
||||||
|
region.degrees = 90
|
||||||
|
elseif rotateValue == "false" then
|
||||||
|
region.degrees = 0
|
||||||
|
else
|
||||||
|
region.degrees = tonumber(rotateValue)
|
||||||
|
end
|
||||||
|
if region.degrees == 90 then region.rotate = true end
|
||||||
|
|
||||||
local tuple = readTuple()
|
local tuple = readTuple()
|
||||||
local x = parseInt(tuple[1])
|
local x = parseInt(tuple[1])
|
||||||
|
|||||||
@ -44,6 +44,7 @@ function TextureAtlasRegion.new ()
|
|||||||
self.y = 0
|
self.y = 0
|
||||||
self.index = 0
|
self.index = 0
|
||||||
self.rotate = false
|
self.rotate = false
|
||||||
|
self.degrees = 0
|
||||||
self.texture = nil
|
self.texture = nil
|
||||||
setmetatable(self, TextureAtlasRegion)
|
setmetatable(self, TextureAtlasRegion)
|
||||||
|
|
||||||
|
|||||||
@ -61,6 +61,11 @@ function MeshAttachment:updateUVs ()
|
|||||||
local v = 0
|
local v = 0
|
||||||
local width = 0
|
local width = 0
|
||||||
local height = 0
|
local height = 0
|
||||||
|
|
||||||
|
local regionUVs = self.regionUVs
|
||||||
|
if not self.uvs or (#self.uvs ~= #regionUVs) then self.uvs = utils.newNumberArray(#regionUVs) end
|
||||||
|
local uvs = self.uvs
|
||||||
|
|
||||||
if not self.region then
|
if not self.region then
|
||||||
u = 0
|
u = 0
|
||||||
v = 0
|
v = 0
|
||||||
@ -70,32 +75,48 @@ function MeshAttachment:updateUVs ()
|
|||||||
local region = self.region
|
local region = self.region
|
||||||
local textureWidth = region.page.width
|
local textureWidth = region.page.width
|
||||||
local textureHeight = region.page.height
|
local textureHeight = region.page.height
|
||||||
if region.rotate then
|
|
||||||
|
if region.degrees == 90 then
|
||||||
u = region.u - (region.originalHeight - region.offsetY - region.height) / textureWidth
|
u = region.u - (region.originalHeight - region.offsetY - region.height) / textureWidth
|
||||||
v = region.v - (region.originalWidth - region.offsetX - region.width) / textureHeight
|
v = region.v - (region.originalWidth - region.offsetX - region.width) / textureHeight
|
||||||
width = region.originalHeight / textureWidth
|
width = region.originalHeight / textureWidth
|
||||||
height = region.originalWidth / textureHeight
|
height = region.originalWidth / textureHeight
|
||||||
|
local i = 0
|
||||||
|
local n = #uvs
|
||||||
|
while i < n do
|
||||||
|
uvs[i + 1] = u + regionUVs[i + 2] * width;
|
||||||
|
uvs[i + 2] = v + (1 - regionUVs[i + 1]) * height;
|
||||||
|
i = i + 2
|
||||||
|
end
|
||||||
|
elseif region.degrees == 180 then
|
||||||
|
u = region.u - (region.originalWidth - region.offsetX - region.width) / textureWidth
|
||||||
|
v = region.v - region.offsetY / textureHeight
|
||||||
|
width = region.originalWidth / textureWidth
|
||||||
|
height = region.originalHeight / textureHeight
|
||||||
|
local i = 0
|
||||||
|
local n = #uvs
|
||||||
|
while i < n do
|
||||||
|
uvs[i + 1] = u + (1 - regionUVs[i + 1]) * width;
|
||||||
|
uvs[i + 2] = v + (1 - regionUVs[i + 2]) * height;
|
||||||
|
i = i + 2
|
||||||
|
end
|
||||||
|
elseif region.degrees == 270 then
|
||||||
|
u = region.u - region.offsetY / textureWidth
|
||||||
|
v = region.v - region.offsetX / textureHeight
|
||||||
|
width = region.originalHeight / textureWidth
|
||||||
|
height = region.originalWidth / textureHeight
|
||||||
|
local i = 0
|
||||||
|
local n = #uvs
|
||||||
|
while i < n do
|
||||||
|
uvs[i + 1] = u + (1 - regionUVs[i + 2]) * width;
|
||||||
|
uvs[i + 2] = v + regionUVs[i + 1] * height;
|
||||||
|
i = i + 2
|
||||||
|
end
|
||||||
else
|
else
|
||||||
u = region.u - region.offsetX / textureWidth;
|
u = region.u - region.offsetX / textureWidth;
|
||||||
v = region.v - (region.originalHeight - region.offsetY - region.height) / textureHeight;
|
v = region.v - (region.originalHeight - region.offsetY - region.height) / textureHeight;
|
||||||
width = region.originalWidth / textureWidth;
|
width = region.originalWidth / textureWidth;
|
||||||
height = region.originalHeight / textureHeight;
|
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
|
|
||||||
while i < n do
|
|
||||||
uvs[i + 1] = u + regionUVs[i + 2] * width;
|
|
||||||
uvs[i + 2] = v + height - regionUVs[i + 1] * height;
|
|
||||||
i = i + 2
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local i = 0
|
local i = 0
|
||||||
local n = #uvs
|
local n = #uvs
|
||||||
while i < n do
|
while i < n do
|
||||||
@ -104,6 +125,7 @@ function MeshAttachment:updateUVs ()
|
|||||||
i = i + 2
|
i = i + 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function MeshAttachment:applyDeform (sourceAttachment)
|
function MeshAttachment:applyDeform (sourceAttachment)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user